Skip to content

fix: Add path traversal protection for schema file loading#380

Merged
cameroncooke merged 2 commits into
mainfrom
fix/path-traversal-vuln-1596
Apr 30, 2026
Merged

fix: Add path traversal protection for schema file loading#380
cameroncooke merged 2 commits into
mainfrom
fix/path-traversal-vuln-1596

Conversation

@fix-it-felix-sentry
Copy link
Copy Markdown
Contributor

Summary

This PR fixes a path traversal vulnerability in the structured output schema loading code by adding validation to ensure that resolved file paths remain within the intended schemas directory.

Changes

  • Added path traversal protection in schemaPathFor() function to validate schema file paths
  • Added path traversal protection in getMcpOutputSchema() for the common schema file path
  • Both checks ensure that resolved paths start with the schemas directory path, preventing directory traversal attacks

Security Context

This addresses a Semgrep security finding where file paths were constructed from potentially untrusted data without sufficient validation. While the code already had regex validation for schema names and versions, it didn't prevent path traversal sequences like ../ from escaping the intended directory.

The fix uses path.resolve() to normalize paths and validates that the resolved path stays within the schemas directory boundary.

Testing

Existing tests in src/core/__tests__/structured-output-schema.test.ts should pass, validating that:

  • Schema bundling continues to work correctly
  • All manifest-declared output schemas resolve successfully
  • The schema cache functions properly

References


🤖 Generated by fix-it-felix-sentry[bot]

Add validation to prevent path traversal vulnerabilities when loading
structured output schema files. The fix ensures that resolved file paths
remain within the intended schemas directory by validating that the
resolved path starts with the schemas directory path.

This addresses a potential security issue where malicious input could
potentially manipulate file paths through path traversal sequences.

The fix adds checks in two locations:
1. In schemaPathFor() for schema files
2. In getMcpOutputSchema() for the common schema file

Resolves: https://linear.app/getsentry/issue/VULN-1596
Resolves: https://linear.app/getsentry/issue/ENG-7560

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 210384d. Configure here.

Comment thread src/core/structured-output-schema.ts Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/xcodebuildmcp@380

commit: 599fce8

@cameroncooke cameroncooke merged commit 77a73cc into main Apr 30, 2026
33 checks passed
@cameroncooke cameroncooke deleted the fix/path-traversal-vuln-1596 branch April 30, 2026 18:24
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.

2 participants