Skip to content

Conversation

jesusmpc
Copy link
Collaborator

@jesusmpc jesusmpc commented Oct 1, 2025

Potential fix for https://github.com/InditexTech/weavejs-backend/security/code-scanning/9

To fix the issue, ensure that any file path created from user input (here, roomId and imageId) is strictly contained within the intended directory, temp, under the current working directory. After constructing the file path, normalize it with path.resolve() and, optionally, fs.realpathSync() to resolve symlinks. Check that the resolved path starts with the base temp folder path. If it does not, return a 400 error and skip further processing. This must be applied before writing or deleting files (saveBase64ToFile, fs.rmSync), on every code path beginning at line 41 (where the path is first constructed).

Implementation steps:

  1. Define a const baseTempDir = path.join(process.cwd(), "temp") at the top of the controller.
  2. When creating filePath, use path.resolve(baseTempDir, fileName).
  3. After resolving, check if filePath starts with baseTempDir.
  4. If not, return a 400 error and do not proceed.
  5. Use filePath as before only after this validation.
    No new dependencies are needed beyond Node’s built-in path and fs modules.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…n path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link

sonarqubecloud bot commented Oct 1, 2025

@jesusmpc jesusmpc marked this pull request as ready for review October 1, 2025 15:21
@jesusmpc jesusmpc merged commit 8267fb3 into main Oct 1, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant