Files
pbakaus_impeccable/server/lib/validation.js
T
Paul BakausandClaude Opus 4.6 b628e208e3 Harden API endpoints: input validation, error sanitization, security headers
- Add shared validation helper (server/lib/validation.js) with ID regex, provider/type allowlists
- Validate all route params against allowlists before filesystem operations to prevent path traversal
- Strip stack traces and error.message from production error responses (generic "Internal server error")
- Sanitize filenames in Content-Disposition headers
- Add X-Content-Type-Options: nosniff and X-Frame-Options: DENY to dev server static responses
- Add path traversal (.. ) checks to all static file handlers and catch-all fetch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 09:58:05 -08:00

25 lines
737 B
JavaScript

// Shared validation helpers for input sanitization
// Only allow alphanumeric, hyphens, and underscores in IDs
export const VALID_ID = /^[a-zA-Z0-9_-]+$/;
export const ALLOWED_PROVIDERS = ['cursor', 'claude-code', 'gemini', 'codex', 'agents', 'universal'];
export const ALLOWED_TYPES = ['skill', 'command'];
export function isValidId(id) {
return typeof id === 'string' && VALID_ID.test(id);
}
export function isAllowedProvider(provider) {
return ALLOWED_PROVIDERS.includes(provider);
}
export function isAllowedType(type) {
return ALLOWED_TYPES.includes(type);
}
// Sanitize a filename for use in Content-Disposition headers
export function sanitizeFilename(filename) {
return filename.replace(/[^a-zA-Z0-9._-]/g, '');
}