Skip to content

fix(core): enforce JSON requests in FsModuleLoader - #36137

Merged
nathanwhit merged 2 commits into
denoland:mainfrom
nathanwhit:fix/fs-module-loader-json-types
Jul 20, 2026
Merged

nathanwhit merged 2 commits into
denoland:mainfrom
nathanwhit:fix/fs-module-loader-json-types

Conversation

@nathanwhit

Copy link
Copy Markdown
Member

Summary

  • reject non-JSON files when FsModuleLoader receives a JSON module request
  • return a TypeError with the actual module type and specifier
  • cover JavaScript, extensionless, and valid JSON files

Details

FsModuleLoader already rejected JSON files loaded without the JSON import attribute, but it did not enforce the reverse mismatch. A .js or extensionless file requested as JSON could therefore be returned as a JavaScript module.

The loader now validates the requested and selected module types before reading the source.

Validation

  • ./tools/format.js
  • cargo check -p deno_core
  • cargo test -p deno_core fs_module_loader -- --nocapture

@nathanwhit
nathanwhit merged commit e0431ff into denoland:main Jul 20, 2026
267 of 270 checks passed
bartlomieju pushed a commit that referenced this pull request Jul 23, 2026
## Summary

- reject non-JSON files when `FsModuleLoader` receives a JSON module
request
- return a `TypeError` with the actual module type and specifier
- cover JavaScript, extensionless, and valid JSON files

## Details

`FsModuleLoader` already rejected JSON files loaded without the JSON
import attribute, but it did not enforce the reverse mismatch. A `.js`
or extensionless file requested as JSON could therefore be returned as a
JavaScript module.

The loader now validates the requested and selected module types before
reading the source.

## Validation

- `./tools/format.js`
- `cargo check -p deno_core`
- `cargo test -p deno_core fs_module_loader -- --nocapture`
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