Skip to content

fix: Streaming file download bypasses afterFind file trigger authorization (GHSA-hpm8-9qx6-jvwv)#10361

Merged
mtrezza merged 2 commits intoparse-community:alphafrom
mtrezza:fix/GHSA-hpm8-9qx6-jvwv-v9
Mar 30, 2026
Merged

fix: Streaming file download bypasses afterFind file trigger authorization (GHSA-hpm8-9qx6-jvwv)#10361
mtrezza merged 2 commits intoparse-community:alphafrom
mtrezza:fix/GHSA-hpm8-9qx6-jvwv-v9

Conversation

@mtrezza
Copy link
Copy Markdown
Member

@mtrezza mtrezza commented Mar 30, 2026

Issue

Streaming file download bypasses afterFind file trigger authorization (GHSA-hpm8-9qx6-jvwv)

Summary by CodeRabbit

  • Bug Fixes

    • Authorization enforcement for file downloads has been improved to properly validate user sessions for all download types, including partial content requests.
    • Invalid or missing session tokens now correctly result in access denial for file downloads.
  • Tests

    • Added comprehensive test coverage for file download authorization scenarios to ensure proper access control enforcement.

@parse-github-assistant
Copy link
Copy Markdown

parse-github-assistant bot commented Mar 30, 2026

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement.

@parseplatformorg
Copy link
Copy Markdown
Contributor

parseplatformorg commented Mar 30, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 34679e8d-063f-4311-ab2c-38ecbca6454c

📥 Commits

Reviewing files that changed from the base of the PR and between 71b24f2 and f79d7ed.

📒 Files selected for processing (2)
  • spec/vulnerabilities.spec.js
  • src/Routers/FilesRouter.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Routers/FilesRouter.js
  • spec/vulnerabilities.spec.js

📝 Walkthrough

Walkthrough

Adds per-request auth resolution for file requests and ensures Parse.File afterFind triggers run before ranged (streaming) responses; applies trigger-provided responseHeaders and forceDownload for streamed file downloads and uses resolved auth for metadata and get handlers.

Changes

Cohort / File(s) Summary
Vulnerability tests
spec/vulnerabilities.spec.js
Adds tests for GHSA-hpm8-9qx6-jvwv validating afterFind(Parse.File) behavior for ranged (streaming) and non-streaming downloads with and without X-Parse-Session-Token; asserts HTTP 403/206 and trigger-thrown forbidden behavior.
Files router auth & streaming
src/Routers/FilesRouter.js
Adds static async _resolveAuth(req, config) to derive per-request auth from headers and uses fileAuth in getHandler/metadataHandler trigger invocations. For streamable GETs, runs afterFind before setting/overriding response headers and before calling filesController.handleFileStream; honors afterFind.responseHeaders and afterFind.forceDownload.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FilesRouter
    participant Auth
    participant Triggers
    participant FilesController

    Client->>FilesRouter: GET /files/:id (Range?, X-Parse-Session-Token)
    FilesRouter->>Auth: _resolveAuth(req, config)
    Auth-->>FilesRouter: fileAuth (user session or null)
    FilesRouter->>Triggers: run afterFind(Parse.File, fileAuth)
    alt afterFind denies access
        Triggers-->>FilesRouter: throw OPERATION_FORBIDDEN / error
        FilesRouter-->>Client: 403 Forbidden
    else afterFind allows / modifies response
        Triggers-->>FilesRouter: { responseHeaders, forceDownload? }
        FilesRouter->>FilesController: handleFileStream(fileId, headers, range)
        FilesController-->>Client: 206 Partial Content or 200 OK (stream)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description only provides the issue link but is missing key sections like Approach and Tasks from the template. Expand the description to include the Approach section explaining the changes and confirm Tasks completion (tests added, security check status).
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main security fix: streaming file downloads now properly enforce afterFind trigger authorization checks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.52%. Comparing base (54c835e) to head (f79d7ed).
⚠️ Report is 2 commits behind head on alpha.

Files with missing lines Patch % Lines
src/Routers/FilesRouter.js 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            alpha   #10361      +/-   ##
==========================================
- Coverage   92.52%   92.52%   -0.01%     
==========================================
  Files         192      192              
  Lines       16554    16566      +12     
  Branches      231      231              
==========================================
+ Hits        15316    15327      +11     
- Misses       1216     1217       +1     
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Routers/FilesRouter.js (1)

211-225: ⚠️ Potential issue | 🟠 Major

The ranged-download path still drops the afterFind result.

This now enforces validators, but the hook result is discarded. At minimum, forceDownload and responseHeaders mutations are ignored on streamed downloads, so the ranged path still behaves differently from the buffered branch.

🔧 Apply the hook result before starting the stream
       if (isFileStreamable(req, filesController)) {
-        await triggers.maybeRunFileTrigger(
+        const afterFind = await triggers.maybeRunFileTrigger(
           triggers.Types.afterFind,
           { file, forceDownload: false, responseHeaders: { ...defaultResponseHeaders } },
           config,
           fileAuth
         );
-        for (const [key, value] of Object.entries(defaultResponseHeaders)) {
+        if (afterFind?.file?._name && afterFind.file._name !== filename) {
+          filename = afterFind.file._name;
+          contentType = mime.getType(filename);
+        }
+        if (afterFind?.forceDownload) {
+          res.set('Content-Disposition', `attachment;filename=${afterFind.file._name}`);
+        }
+        for (const [key, value] of Object.entries(afterFind?.responseHeaders ?? defaultResponseHeaders)) {
           res.set(key, value);
         }
         filesController.handleFileStream(config, filename, req, res, contentType).catch(() => {
Based on learnings: In parse-community/parse-server, the `responseHeaders` object exposed to `afterFind` file hooks (Parse.Cloud.afterFind(Parse.File, ...)) is intentionally fully mutable by the server administrator.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Routers/FilesRouter.js` around lines 211 - 225, The ranged-download
branch currently calls triggers.maybeRunFileTrigger but ignores its result;
change to await and capture the result of triggers.maybeRunFileTrigger (called
with triggers.Types.afterFind, { file, forceDownload: false, responseHeaders: {
...defaultResponseHeaders } }, config, fileAuth), then apply any mutations from
the returned object—merge/overwrite res headers from result.responseHeaders and
use result.forceDownload when invoking filesController.handleFileStream; finally
call filesController.handleFileStream(config, filename, req, res, contentType)
(or pass a param to enforce download if handleFileStream supports it) after
applying headers and keep the existing .catch error handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Routers/FilesRouter.js`:
- Around line 124-137: The helper static method _resolveAuth currently swallows
all exceptions from auth.getAuthForSessionToken and returns null, which hides
invalid/expired token errors; change it so that only a missing session token
returns null and any errors thrown by auth.getAuthForSessionToken are not
downgraded — either rethrow the caught error or propagate it (do not return null
on catch). Update static async _resolveAuth to call auth.getAuthForSessionToken
and let its errors bubble up (or rethrow them) so callers can surface
authentication failures instead of treating them as anonymous access.

---

Outside diff comments:
In `@src/Routers/FilesRouter.js`:
- Around line 211-225: The ranged-download branch currently calls
triggers.maybeRunFileTrigger but ignores its result; change to await and capture
the result of triggers.maybeRunFileTrigger (called with
triggers.Types.afterFind, { file, forceDownload: false, responseHeaders: {
...defaultResponseHeaders } }, config, fileAuth), then apply any mutations from
the returned object—merge/overwrite res headers from result.responseHeaders and
use result.forceDownload when invoking filesController.handleFileStream; finally
call filesController.handleFileStream(config, filename, req, res, contentType)
(or pass a param to enforce download if handleFileStream supports it) after
applying headers and keep the existing .catch error handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91d39f66-9744-4560-a4af-ffd3e53bfe21

📥 Commits

Reviewing files that changed from the base of the PR and between 54c835e and dc189b8.

📒 Files selected for processing (2)
  • spec/vulnerabilities.spec.js
  • src/Routers/FilesRouter.js

@mtrezza
Copy link
Copy Markdown
Member Author

mtrezza commented Mar 30, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mtrezza mtrezza changed the title fix: GHSA-hpm8-9qx6-jvwv v9 fix: Streaming file download bypasses afterFind file trigger authorization (GHSA-hpm8-9qx6-jvwv) Mar 30, 2026
@mtrezza mtrezza force-pushed the fix/GHSA-hpm8-9qx6-jvwv-v9 branch from 71b24f2 to f79d7ed Compare March 30, 2026 22:52
@mtrezza mtrezza merged commit a0b0c69 into parse-community:alpha Mar 30, 2026
22 of 24 checks passed
parseplatformorg pushed a commit that referenced this pull request Mar 30, 2026
## [9.7.1-alpha.1](9.7.0...9.7.1-alpha.1) (2026-03-30)

### Bug Fixes

* Streaming file download bypasses afterFind file trigger authorization ([GHSA-hpm8-9qx6-jvwv](GHSA-hpm8-9qx6-jvwv)) ([#10361](#10361)) ([a0b0c69](a0b0c69))
@parseplatformorg
Copy link
Copy Markdown
Contributor

🎉 This change has been released in version 9.7.1-alpha.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants