Skip to content

feat(fetch): support file URLs via opt-in dispatcher interceptor#4907

Open
mcollina wants to merge 2 commits intomainfrom
feat/file-url-custom-dispatcher
Open

feat(fetch): support file URLs via opt-in dispatcher interceptor#4907
mcollina wants to merge 2 commits intomainfrom
feat/file-url-custom-dispatcher

Conversation

@mcollina
Copy link
Member

@mcollina mcollina commented Mar 18, 2026

Summary

  • add a new interceptors.file() dispatcher interceptor for handling file: URLs
  • keep policy app-defined and deny-by-default via allow() callback
  • do not rely on Node process permissions
  • wire fetch() file scheme path to dispatcher so custom dispatchers/interceptors can handle it

Details

  • New interceptor: lib/interceptor/file.js
  • Exported via interceptors.file in index.js
  • Added types in types/interceptors.d.ts
  • Added docs in docs/docs/api/Dispatcher.md

Tests

  • test/interceptors/file.js
    • serves allowed files
    • blocks disallowed files
    • passes through non-file requests
  • test/fetch/file-url-interceptor.js
    • default fetch(file://...) rejects
    • fetch(file://...) works with custom file interceptor
    • disallowed policy still rejects

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 86.24339% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.88%. Comparing base (2885361) to head (bef3811).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/interceptor/file.js 85.63% 26 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4907      +/-   ##
==========================================
- Coverage   92.90%   92.88%   -0.02%     
==========================================
  Files         112      113       +1     
  Lines       35638    35821     +183     
==========================================
+ Hits        33109    33272     +163     
- Misses       2529     2549      +20     

☔ 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.

}))
}
case 'file:': {
// For now, unfortunate as it is, file URLs are left as an exercise for the reader.
Copy link
Member

Choose a reason for hiding this comment

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

This comment comes from the spec and should be kept.

@mcollina
Copy link
Member Author

What do you think @KhafraDev, will this be a better model?

@KhafraDev
Copy link
Member

Yes, I have no problems with it. Is there an interest in this again, I saw my old PR getting activity too?

travisbreaks

This comment was marked as spam.

@mcollina
Copy link
Member Author

Yes, I have no problems with it. Is there an interest in this again, I saw my old PR getting activity too?

it was marked as semver-major, and I took a look at it again before cutting undici 8.

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.

4 participants