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

General Approach:
Sanitize and validate roomId and imageId before using them to build filesystem paths. There are two principal approaches: (1) restrict roomId and imageId to simple, safe file/folder names (no slashes or special chars), or (2) use path normalization and restrict all constructed paths to a fixed root directory.

Best solution for this case:
Given the context (image storage in a /temp subdirectory), the simplest secure approach is to restrict roomId and imageId to safe filenames (no slashes, path traversal, or special characters). This can be accomplished using a library such as sanitize-filename, which removes unsafe characters. Since we are using only code shown, we'll apply a minimal regex check to only allow alphanumeric (and, optionally, - or _) characters and reject anything else. If invalid input is detected, return a 400 error.

Implementation steps:

  • Insert validation code for both roomId and imageId at the start of the controller, after line 24.
  • Only allow strings matching /^[a-zA-Z0-9_-]+$/ for both.
  • If either is invalid, send a 400 error, do not proceed further.
  • No changes to path-building logic since now both input values are sanitized and safe.
  • No external dependencies required.

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>
@jesusmpc jesusmpc marked this pull request as ready for review October 1, 2025 15:15
Copy link

sonarqubecloud bot commented Oct 1, 2025

@jesusmpc jesusmpc merged commit 0195fff 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