reject path-traversal segments in coordinate ids and versions#12410
reject path-traversal segments in coordinate ids and versions#12410jmestwa-coder wants to merge 3 commits into
Conversation
gnodet
left a comment
There was a problem hiding this comment.
Review: Reject path-traversal segments in coordinate ids and versions
This is a genuine and valuable security fix — thank you for working on it! I have a few suggestions to strengthen it before it can be merged.
Findings
1. [High] Incomplete coverage of groupId path-traversal
The current check only rejects exact matches of "." and ".." as the entire coordinate string. However, for groupId, Maven maps dots to path separators — so a groupId like org..evil becomes org/../evil/ in the local repository layout, which is a path traversal that bypasses this check.
Consider either:
- Extending the fix to check each dot-delimited segment of groupIds for
"."and"..", or - Filing a follow-up issue explicitly documenting this remaining gap.
2. [Medium] No Jira issue referenced
The project's commit convention requires [MNG-XXXX] <description> for fixes. Please create a Jira issue and reference it in the commit message — especially for security-related changes.
3. [Medium] Test coverage gaps
- Tests cover
".."but not"."— both are rejected by the code and should be tested. - Tests don't cover groupId traversal (only artifactId and version).
- Consider adding a test for
"."as a version as well.
4. [Low] CI has not run
No checks have been reported on the branch. Please run mvn verify (and ideally mvn -Prun-its verify for Core ITs) before resubmitting.
This review does not replace specialized tools such as CodeRabbit, Sourcery, or SonarCloud.
Reviewed with Claude Code on behalf of @gnodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.
|
thanks for the review, went through each point:
|
elharo
left a comment
There was a problem hiding this comment.
This needs an issue that clearly describes and provides an example fo the problem
…ersions Signed-off-by: Syed Mohammed Nayyar <jmestwa@gmail.com>
…ersal segments covers '.' as artifactId and dependency version, plus groupId '..', in both the maven-impl and compat maven-model-builder validators.
9955586 to
c8ac7a0
Compare
|
filed #12427 with the description and a worked example (artifactId |
| } | ||
|
|
||
| /** | ||
| * An id or version made up only of {@code .} or {@code ..} is a filesystem path-traversal segment. The dotted |
There was a problem hiding this comment.
I don't think this is true. The problem is mapping straight into a path traversal segment, not that these are the names. If you can find evidence that these are not legal names, please post it.
There was a problem hiding this comment.
fair point, I don't have evidence that . or .. are illegal names as such. the actual problem is the default local repository layout using artifactId/version verbatim as directory names, which turns these values into literal ./.. path segments. reworded the javadoc in both validators to say the rejection is due to that mapping, not the names themselves.
There was a problem hiding this comment.
On Unix and probably other systems . and .. are legal filenames. Dealing with this is a classic Unix sysadmin interview question.
There was a problem hiding this comment.
agreed. the reworded javadoc makes no claim the names are illegal, only that the default layout uses them verbatim as directory names so they resolve as the current/parent directory. the rejection is pinned entirely on that mapping.
There was a problem hiding this comment.
The names are illegal, see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html, section 4.13:
The special filename dot shall refer to the directory specified by its predecessor. The special filename dot-dot shall refer to the parent directory of its predecessor directory. As a special case, in the root directory, dot-dot may refer to the root directory itself.
You can't create a file named . or ...
There was a problem hiding this comment.
Or did you meant reserved instead of illegal maybe ?
There was a problem hiding this comment.
The section you cite refers to pathname resolution, not to pathnames themselves. In practice on most (all?) Unix and Unix like systems it is possible to create a file named "." or ".." as unwise as that might be.
There was a problem hiding this comment.
Can you give me a reproducible way to create a file or directory named . or .. ?
echo > .
zsh: is a directory: .
There was a problem hiding this comment.
In python, open() returns 21 (EISDIR) on both . and ...
Fixes #12427.
Coordinate ids and versions equal to
.or..pass model validation but land as raw directory segments when an artifact is mapped to its local repository path (groupId/artifactId/version/...):isValidCoordinatesId/isValidIdaccept them because every character is individually allowed, so an artifactId of..is a path-traversal segmentvalidateVersiononly bans the filesystem metacharacters, so a dependency version of..slips through the same wayReject
.and..at each check. Regression test added in both modules; it fails on the unpatched validators and passes after.mvn verifyto make sure basic checks pass.