fix(apps/server/rest): enhance path validation and update CORS settings#77
fix(apps/server/rest): enhance path validation and update CORS settings#77
Conversation
…ure local development compatibility
There was a problem hiding this comment.
Pull Request Overview
This PR enhances security by updating path validation using a new isSafePath function and simplifies CORS settings for improved local development.
- Replaces isRelativePath with isSafePath across file operations.
- Updates error messages to a more generic "Invalid path" upon validation failure.
- Simplifies CORS origins to only include local development endpoints.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/server/rest/src/modules/files/utils/index.ts | Introduces and documents the new isSafePath function for path validation. |
| apps/server/rest/src/modules/files/files.service.ts | Updates validations from isRelativePath to isSafePath and adjusts error messages accordingly. |
| apps/server/rest/src/main.ts | Simplifies CORS settings by removing production domain origins for local development. |
Files not reviewed (1)
- apps/server/rest/package.json: Language not supported
Comments suppressed due to low confidence (2)
apps/server/rest/src/modules/files/files.service.ts:67
- [nitpick] The updated error message 'Invalid path' is generic and may not provide enough context. Consider adding more details to help diagnose the invalid path condition during development.
throw new HttpException('Invalid path', HttpStatus.BAD_REQUEST);
apps/server/rest/src/modules/files/utils/index.ts:9
- It would be beneficial to include unit tests for isSafePath to verify its behavior with empty, relative, and edge-case paths.
export const isSafePath = (basePath: string, targetPath?: string): boolean => {
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the security of path handling in the REST server by replacing the old isRelativePath function with a new isSafePath verification and simplifies CORS settings to favor local development.
- Update and rename the path validation function from isRelativePath to isSafePath with improved logic.
- Update FilesService to consistently use the new path check and throw standardized error messages.
- Simplify CORS origins in main.ts and add a new Jest config for unit testing.
Reviewed Changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| apps/server/rest/src/modules/files/utils/index.ts | Replaces isRelativePath with improved isSafePath validation. |
| apps/server/rest/src/modules/files/utils/index.test.ts | Provides unit tests for the updated isSafePath function. |
| apps/server/rest/src/modules/files/files.service.ts | Updates path validation checks to use isSafePath. |
| apps/server/rest/src/main.ts | Simplifies CORS settings for local development. |
| apps/server/rest/jest.config.ts | Introduces Jest configuration for testing. |
Files not reviewed (2)
- apps/server/rest/package.json: Language not supported
- apps/server/rest/tsconfig.json: Language not supported
Comments suppressed due to low confidence (2)
apps/server/rest/src/modules/files/files.service.ts:66
- [nitpick] The error message 'Invalid path' is generic. Consider providing a more specific error message that indicates which part of the path failed validation.
if (!isSafePath(this.basePath, path)) {
apps/server/rest/src/modules/files/utils/index.test.ts:29
- Consider adding a test case to verify that an undefined targetPath is handled correctly by isSafePath, ensuring comprehensive test coverage for optional parameters.
const emptyPath = '';
…gs (#77) * feat(rest/files): update path validation to use isSafePath for improved security * fix(files/utils): correct isSafePath function to return true for empty targetPath * fix(rest): update CORS settings to remove unnecessary origins and ensure local development compatibility * feat: Refactor code structure for improved readability and maintainability * chore(package): update CI and deploy scripts for correct command execution * test(files/utils): simplify isSafePath tests by removing redundant basePath declarations * comment(files/service): add TODO comment for modular error handling
FIX
isSafePath, ensuring that invalid paths are properly handled.isSafePathfunction to allow empty target paths.FEAT
jest