-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Handle windows-style bare specifiers in exports #30169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
1 or 3 sounds good to me. |
i think normalizing the specifier to the platform would be in the realm of "expected behavior"? |
Yes-ish. The problem is that we're crossing streams. It's the same configuration for both ESM and CJS. ESM operates on file URLs so "normalizing" means converting those to platform file system paths. CJS operates on file system paths so "normalizing" means first mapping relative path segments to URL segments, then mapping, and then mapping the result back to file system paths. The question is less "should we normalize" and more "what do we consider our input/output formats to be" so we can normalize correctly. |
As long as it is documented, I don't have a preference on solution chosen. If we do go with 3. however I would suggest the following types and coercions:
Conversion happens lazily like most things. People can use auditing like linters to do ahead of time checks. The URLs are resolved against the location of the // will ensure trailing / and remove fragment and query
// don't need this if you aren't checking location after resolve
pkgRoot = new URL('.', fileURLOfPackageJSON);
resolvedExportValue = new URL(value, pkgRoot);
// could do a pathname check to see if it stayed in the pkgRoot?
// idk, seems more of an auditing problem than a need to prevent this behavior
// only used by CJS
// this strips query/fragment but CJS doesn't support those to begin with
filename = fileURLToPath(resolvedExportValue);
|
My current thinking is that we should officially narrow the scope of This will mean that code can "exploit" backslash on Windows (under EDIT: Fixed some grammar. |
By “specifiers that are a package name” you mean, exports only “kicks in” when the resolved specifier started with a bare specifier? |
Yep. Or to be more precise: when it's a "package name specifier" which is a subset of all bare specifiers. E.g. |
Since this type of specifier resolution would affect both CJS and ESM would
it make sense for us to transfer this issue to nodejs/node?
…On Tue, Oct 29, 2019 at 1:27 PM Jan Olaf Krems ***@***.***> wrote:
Yep. Or to be more precise: when it's a "package name specifier" which is
a subset of all bare specifiers. E.g. \0%$! is a bare specifier but not
something that would trigger exports (a "package name").
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/nodejs/modules/issues/356?email_source=notifications&email_token=AADZYV24EHWZ2Q5YCUGKYUDQRBXATA5CNFSM4IGGAUN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECRMQZA#issuecomment-547539044>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADZYV72ROVWTTQGTXVSQ2DQRBXATANCNFSM4IGGAUNQ>
.
|
одно спотыкание и мы<clang-format.json> |
Is this still relevant? |
I confirm the behavior is still there. Option 3 makes sense in my opinion. |
There's currently a loophole in CJS exports:
The above will load
y.js
at least on Windows even ifx
usesexports
and didn't whitelist the path. This happens because the specifier isn't recognized as anexports
specifier.There's three possible ways out:
x
usesexports
treat it as "not mapped", no matter what the subpath is.There are other potential loopholes like the following:
@scope/../any/file.js
: Doesn't match the RegExp, allows access toany/file.js
.It's not quite clear if we can plug all holes in CJS but there's likely some way of doing it.
The text was updated successfully, but these errors were encountered: