-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
pathGroups using minimatch instead of real regexes #1632
Comments
I find regexes in config files to be a massive antipattern, and am not interested in adding that. Can you give me a concrete example of a pathGroups setting you're trying, and the code you want it to work on? |
Yes, the codebase should indeed use proper root based imports and no relative ones, but that isn't necessarily the case.
Which runs perfectly fine with my fork with proper regexes. |
I'm not interested in a regex approach; I'd rather fix the way we're using minimatch. In other words, I'd expect you to be able to use globs - multiple globs in an array if possible - to achieve what you want, and if you can't right now, let's make that happen. |
What's the reason for not wanting to support regex? |
Supporting regexes in eslint configs leads to all sorts of CVE vulnerabilities about catastrophic backtracking, for one - but also I think it's overpowered, and it'd be better to explicitly support the needed features. As for "better known", globs are what eslint itself uses, as well as gitignore and npmignore, so I'm not sure that's true. |
Okay, didn't think about redos here. Was there some concrete example for this in the past, I am unfamiliar with eslints internal happenings and in which case an attacker would be able to inject things into my eslint config (apart from all the code usually pulled unseen from npm anyway, which could do whatever anyway?). I pretty much remember my university modules about regex and FSMs, never had any deeper looks into globs. :D I suppose we could add some way to strip of suffixes from the name via config before minimatching and achieve the same. |
Yes, there was a plethora of CVEs filed on eslint plugins a year or three ago for exactly this. |
I also want to match an arbitrary number of parent directories. I have a web app that imports external dependencies from I'm currently using |
@tulir |
Pretty sure it doesn't: > minimatch("../../web_modules/preact.js", "**/web_modules/**")
false
> minimatch("../../web_modules/preact.js", "{.,..,../..,../../..}/web_modules/**")
true |
I'm not too convinced by snowpack as a use case, since this plugin relies on node_modules living on disk, and everything coming from However, this seems like it would be better solved by using a snowpack resolver instead of the node resolver + a bunch of rule configuration overrides. |
Would you be okay with adding an option that strips of an arbitrary amount of |
That still seems like a hacky workaround for not using a snowpack resolver, if you're using snowpack. |
|
That doesn't seem like a bug to me. |
So how on the earth can I match both |
This comment has been minimized.
This comment has been minimized.
@Menci |
Issue closable now? I enthusiastically agree that globs are the optimal approach here. |
The issue remains. |
A ton is gained - regexes in eslint config are the sole source of CVEs for the eslint ecosystem afaik, and by avoiding them, we avoid an entire class of vulnerability. |
I am still not clear in which case someone being able to add a regex inside my eslint config is the worst thing that party would be able to do, i.e. in which case would a party be able to add a regex to my config but not to be able to modify my codebase in some other way? |
I agree it's not a legitimate attack vector. However, that doesn't stop the security industry from generating tons of CVEs and thus github and npm audit warnings every time there's a regex in an eslint rule anywhere. The cost isn't worth the benefit. |
Ah, okay, I wasn't aware of that angle. That indeed would be quite annoying. Maybe I should generate some exploit report related to ../../../ paths and force prefixes on everyone. :D |
off topic: |
Coincidentally Dan wrote something about regex vulns:
Let's hope the tooling will change. |
For those trying to select multi-level parent directories, const longParentPath =
"{.," +
Array.from({ length: 10 }, (_, i) => "../".repeat(i + 1).slice(0, -1)).join(",") +
"}"; So Use it in a {
"import/order": [
"warn",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"index",
"sibling",
"unknown",
],
pathGroups: [
{
pattern: `${longParentPath}/Tables/**`,
group: "parent",
position: "before",
},
{
pattern: `${longParentPath}/Models/**`,
group: "parent",
position: "before",
},
{
pattern: `${longParentPath}/Components/**`,
group: "parent",
position: "before",
},
{
pattern: `${longParentPath}/images/**`,
patternOptions: { partial: true },
group: "unknown",
position: "before",
},
],
"newlines-between": "always",
distinctGroup: false,
},
],
} |
The new pathGroup addition is using
minimatch
, this being based on shell glob expansions makes it incredible hard to do differing matching on paths containing../
updots, as these are not easily (if at all) added to the minimatch expression in unspecified depth.Yes, the codebase should import from the roots and not jump up arbitrarily, but sometimes the world is at it is.
This shortcoming is not evident inside the PR tests themselves, as all these prefix with special characters: https://github.com/benmosher/eslint-plugin-import/pull/1386/files
I didn't find a way to express my wanted regex with minimatch, it would be great to have a shortcutting flag to just supply a real regex.
The text was updated successfully, but these errors were encountered: