Skip to content

RTECO-1400 - Add path validation to prevent traversal attacks in artifact handling#487

Merged
fluxxBot merged 2 commits into
mainfrom
RTECO-1400-frogbot
Jun 10, 2026
Merged

RTECO-1400 - Add path validation to prevent traversal attacks in artifact handling#487
fluxxBot merged 2 commits into
mainfrom
RTECO-1400-frogbot

Conversation

@fluxxBot

@fluxxBot fluxxBot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator
  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • Appropriate label is added to auto generate release notes.
  • I used gofmt for formatting the code before submitting the pull request.
  • PR description is clear and concise, and it includes the proposed solution/fix.

@fluxxBot fluxxBot requested a review from a team June 8, 2026 14:00
@fluxxBot fluxxBot added the improvement Automatically generated release notes label Jun 8, 2026
@fluxxBot fluxxBot added the safe to test Approve running integration tests on a pull request label Jun 8, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Jun 8, 2026
agrasth

This comment was marked as off-topic.

agrasth

This comment was marked as off-topic.

@agrasth

agrasth commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

CI Status Summary

All checks are passing. No failures found.

Check Result
CLAssistant ✅ Pass
Check PR Labels ✅ Pass
Go-Sec (ubuntu-latest) ✅ Pass
Lint (macOS) ✅ Pass
Lint (ubuntu) ✅ Pass
Lint (windows) ✅ Pass
Static Check (ubuntu-latest) ✅ Pass
macOS unit tests ✅ Pass
ubuntu unit tests ✅ Pass
windows unit tests ✅ Pass
scan-pull-request ✅ Pass

All 19 check runs across both workflow trigger runs completed successfully. This PR is green and ready for review.

@agrasth agrasth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore.

@agrasth agrasth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore.

@agrasth agrasth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore.

@agrasth agrasth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: RTECO-1400 — Path Traversal Prevention in Maven Artifact Handling

Files reviewed: 1 production file (artifactory/commands/flexpack/maven.go) — 0 test files

Executive Summary

This PR correctly identifies and mitigates a real path traversal risk: Maven coordinates and packaging type extracted from a user-controlled pom.xml were flowing directly into filepath.Join calls without sanitization. The defense-in-depth approach (validating at extraction time and at composition time) is good instinct. Two issues need attention before merge: the new security logic ships with zero test coverage, and the validation uses a denylist rather than an allowlist — the weaker of the two strategies when the allowed character set is well-defined.


Findings

Testing

Major — artifactory/commands/flexpack/maven.go (validateMavenCoordinate) — No tests for new security validation logic

The entire validateMavenCoordinate function and all its call-sites have no test coverage. This is the most impactful gap: security controls without tests are silently broken by future refactors. At minimum, tests should cover:

  • Valid coordinates pass (groupId with dots, version with dashes/dots, SNAPSHOT suffix)
  • .. in any position is rejected
  • / and \ are rejected
  • Null byte (\x00) is rejected
  • Empty string behavior (currently passes — see minor finding below)

Security

Minor — artifactory/commands/flexpack/maven.go:513 — Denylist is weaker than an allowlist for Maven coordinate validation

validateMavenCoordinate blocks .., /, \, and null bytes, but Maven coordinates have a narrow, well-defined character set. An allowlist rejects all future unknown bypass vectors (newlines, semicolons, ANSI codes, encoded characters) without needing to enumerate them:

var mavenCoordinateRe = regexp.MustCompile(`^[a-zA-Z0-9._\-]+$`)

func validateMavenCoordinate(value string) error {
    if value == "" {
        return fmt.Errorf("value is empty")
    }
    if !mavenCoordinateRe.MatchString(value) {
        return fmt.Errorf("value %q contains characters not permitted in Maven coordinates", value)
    }
    return nil
}

This subsumes the existing three checks and adds an empty-string guard.

Functionality

Minor — artifactory/commands/flexpack/maven.go:553 — Defense-in-depth check omits null byte (inconsistent with validateMavenCoordinate)

The secondary check on mainArtifactName tests .. and /\\ but not null bytes, making it a weaker subset of validateMavenCoordinate. To stay consistent and avoid maintaining two parallel denylist snippets that can drift:

// Before:
if strings.Contains(mainArtifactName, "..") || strings.ContainsAny(mainArtifactName, "/\\") {
    return fmt.Errorf("invalid artifact name %q", mainArtifactName)
}

// After:
if err := validateMavenCoordinate(mainArtifactName); err != nil {
    return fmt.Errorf("invalid artifact name: %w", err)
}

Note: mainArtifactName includes - and . separators, both of which are already permitted by the allowlist regex suggested above.


Positive Highlights

  • Null byte check (strings.ContainsRune(value, 0)) is a non-obvious but correct inclusion; many path-traversal validators miss this vector.
  • %w wrapping in error returns preserves error chain semantics for callers using errors.Is / errors.As.
  • Graceful fallback to "jar" for invalid packaging type keeps the tool functional against a malicious pom.xml without crashing.
  • Validating at both extraction time (getMavenArtifactCoordinates) and composition time (addDeployedArtifactsToBuildInfo) is the right defense-in-depth instinct.

Verdict

REQUEST CHANGES

Add unit tests for validateMavenCoordinate before merging — this is security-critical code and must be verifiable.

Comment thread artifactory/commands/flexpack/maven.go
Comment thread artifactory/commands/flexpack/maven.go Outdated
@fluxxBot

Copy link
Copy Markdown
Collaborator Author

The validation only runs on coordinate fields — groupId, artifactId, version, packaging (and the Parent fallbacks). These are Maven coordinates, not filesystem paths. By spec/convention they're restricted to [A-Za-z0-9_.-]:

groupId: dot-separated package-style, e.g. com.example — single dots as separators, never .. or /.
artifactId: e.g. my-app — no separators.
version: e.g. 1.0.0-SNAPSHOT — dots separate segments, never two consecutive (1..0 is invalid).
packaging: jar/war/pom/ear/bundle etc.
None of these can legitimately contain .., /, or .

agrasth
agrasth previously approved these changes Jun 10, 2026
bhanurp
bhanurp previously approved these changes Jun 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👍 Frogbot scanned this pull request and did not find any new security issues.


@bhanurp bhanurp self-requested a review June 10, 2026 05:34
@fluxxBot fluxxBot merged commit d8ae781 into main Jun 10, 2026
19 checks passed
@fluxxBot fluxxBot deleted the RTECO-1400-frogbot branch June 10, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Automatically generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants