Skip to content

Handle windows-style bare specifiers in exports #30169

Description

@hybrist

There's currently a loophole in CJS exports:

require('x\\y.js');

The above will load y.js at least on Windows even if x uses exports and didn't whitelist the path. This happens because the specifier isn't recognized as an exports specifier.

There's three possible ways out:

  1. We detect this case and iff x uses exports treat it as "not mapped", no matter what the subpath is.
  2. We accept this as a loophole.
  3. We normalize the specifier, turning backslashes into slashes.

There are other potential loopholes like the following:

  • @scope/../any/file.js: Doesn't match the RegExp, allows access to any/file.js.
  • TBD

It's not quite clear if we can plug all holes in CJS but there's likely some way of doing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    moduleIssues and PRs related to the module subsystem.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions