Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

odaysec
Copy link
Contributor

@odaysec odaysec commented Oct 13, 2025

Summary of Fixes

Detailed Jira Ticket 馃師MONGOSH-2914

  • packages/build/src/download-center/config.spec.ts

User input (req.url) was being written directly to the HTTP response using res.end(req.url);, making the application vulnerable to reflected cross-site scripting (XSS). A malicious actor could craft a specially formed URL containing HTML or JavaScript, which would be reflected back and executed in a victim鈥檚 browser.

Fix:

  • Imported the escape-html library.
  • Sanitized all user-controlled output before sending it in HTTP responses.

This ensures all HTML-sensitive characters are encoded safely before being returned in the response.
Prevents reflected XSS attacks while preserving the intended functionality of the HTTP handler.

  • packages/snippet-manager/src/snippet-manager.spec.ts

File paths were being constructed using unvalidated user input (req.url) via:

path.join(__dirname, '..', 'test', 'fixtures', '.' + req.url)

This approach allowed potential directory traversal, enabling access to files outside the intended fixtures directory if crafted paths such as ../../ were provided.

  • Introduced a strict validation check using path.resolve() and prefix comparison.

  • Ensured that only paths within the intended fixtures root are served.

  • Updated the file path construction to:

    const fixturesRoot = path.resolve(__dirname, '..', 'test', 'fixtures');
    const requestedPath = path.resolve(fixturesRoot, '.' + req.url);
    if (!requestedPath.startsWith(fixturesRoot + path.sep)) {
      res.writeHead(403, { 'Content-Type': 'text/plain' });
      res.end('Forbidden');
      return;
    }
    const source = createReadStream(requestedPath);

Additional Adjustments:

  • Declared fixturesRoot once outside the request handler for reuse.
  • Applied consistent error handling for invalid paths (returns HTTP 403).

Eliminates directory traversal risks and ensures that only authorized fixture files can be accessed or read during test operations.

  • packages/editor/src/editor.ts

The code dynamically constructed a shell command with:

spawn(editor, [path.basename(tmpDoc)], { shell: true, ... });

When shell: true is enabled, unescaped input in the command arguments can lead to shell injection, where special characters in the file name could alter the executed command or inject arbitrary commands.

Fix:

  • Imported the shell-quote module for secure shell argument escaping.

  • Escaped the filename argument before passing it to spawn.

  • Updated the code to:

    const shellQuote = require('shell-quote');
    spawn(editor, [shellQuote.quote([path.basename(tmpDoc)])], { shell: true, ... });

    Alternatively, to quote both command and arguments:

    spawn(shellQuote.quote([editor, path.basename(tmpDoc)]), { shell: true, ... });

Prevents command injection while preserving the expected shell command behavior.
All user-influenced paths and arguments are now properly escaped before execution.
This fixes request improves the overall security posture of mongosh by introducing:

  • Proper HTML escaping to mitigate XSS,
  • Safe file path resolution to prevent directory traversal,
  • And shell argument sanitization to prevent command injection.

@odaysec odaysec requested a review from a team as a code owner October 13, 2025 21:35
@odaysec odaysec changed the title fix: properly sanitize HTTP output restrict unsafe file path access and escape shell arguments to prevent fix: MONGOSH-2914 properly sanitize HTTP output restrict unsafe file path access and escape shell arguments to prevent Oct 13, 2025
@addaleax
Copy link
Collaborator

I'll quote myself from #2455:

It seems you are creating pull requests across multiple GitHub repositories, potentially based on detecting specific patterns in source code automatically. Unfortunately, it also seems that you are not taking into account the circumstances under which the code in question runs, and what its intended behavior would be. I will close this PR and #2454 as they do not appear to be targeting legitimate vulnerabilities in this software.

For the future, please be encouraged to bring up genuine security issues, but be advised that opening PRs across a broad set of repositories automatically without understanding the target source code will generally not help your reputation as a security researcher, and rather will put your PRs at risk of being marked as spam and reported to GitHub.

@odaysec I will mark this PR as spam and report it to Github. You're not engaging in good-faith conversation here.

@odaysec
Copy link
Contributor Author

odaysec commented Oct 14, 2025

Hi @addaleax,

I feel that your response was unfair and dismissive. I鈥檓 contributing with genuine intentions to improve this project and fix potential issues, not to spam or cause problems. I鈥檇 appreciate it if my efforts could be reviewed objectively and respectfully. I鈥檓 always open to constructive feedback, but please avoid making personal assumptions about my motives.

I understand your concern, but I believe there鈥檚 been a misunderstanding. I鈥檓 not creating PRs for spam or automation purposes, I鈥檓 a security researcher who contributes fixes for real issues that could affect project safety or maintainability. my intention is to help improve the project by identifying potential security or logic flaws and providing direct fixes through PRs.

Thank you for your time.

@odaysec odaysec closed this Oct 14, 2025
@addaleax
Copy link
Collaborator

I鈥檓 always open to constructive feedback,

The relevant feedback was provided on previous PRs: You don't seem to understand the source code you're working on, and your code and your PR descriptions are obviously AI-generated.

The problem is that you've ignored the previous constructive feedback given to you.

I鈥檓 a security researcher who contributes fixes for real issues

Yeah, here's the problem though 鈥撀爊one of the issues you've tried to fix in your 4 PRs so far have been "real issues". You're not helping to improve projects, you're creating noise for maintainers.聽That's spam.

@addaleax addaleax added the invalid This doesn't seem right label Oct 14, 2025
@odaysec
Copy link
Contributor Author

odaysec commented Oct 14, 2025

Thanks for the clarification. I sincerely apologize if my contributions caused any inconvenience. my intention was only to help open source projects by improving security and mitigation areas.

I鈥檇 appreciate it if future discussions could remain respectful and open-minded. Just to clarify, I didn鈥檛 use any AI tools for these PRs, everything was done manually and with good intentions.

Thank you for the feedback. I鈥檒l take it into consideration for future contributions.

@odaysec odaysec deleted the fixdev branch October 14, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.