Skip to content

Validation for Upstream and Locator git.directory fields - #4837

Open
mozesl-nokia wants to merge 2 commits into
kptdev:mainfrom
nokia:upstream-path-validation
Open

mozesl-nokia wants to merge 2 commits into
kptdev:mainfrom
nokia:upstream-path-validation

Conversation

@mozesl-nokia

@mozesl-nokia mozesl-nokia commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

The git.directory field of the Upstream and Locator type are now part of validation, preventing potential upward path traversal out of the repositories' directory.

AI disclaimer:

  • Used Cursor Grok 4.7 to check for additional, similarly unvalidated paths and to validate this solution

Assisted-by: Cursor:grok-4.7
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
@mozesl-nokia
mozesl-nokia requested review from a team October 28, 2026 16:06
@mozesl-nokia mozesl-nokia added the bug Something isn't working label Oct 28, 2026
@mozesl-nokia
mozesl-nokia requested a review from a team October 28, 2026 16:06
@mozesl-nokia mozesl-nokia added go Pull requests that update Go code area/api labels Oct 28, 2026
Copilot AI balanced review requested due to automatic review settings October 28, 2026 16:06
@netlify

netlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 2d8ffa9
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6ae220f1402053d2dd18b663
😎 Deploy Preview https://deploy-preview-4837--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The path validation accepts mixed-separator paths that escape the repository on Linux/macOS, leaving fetch/update guards vulnerable to directory traversal.

1 open issue
What changed in this PR

This PR adds validation for Git directory paths in kpt package metadata and fetch operations to prevent upward traversal outside cloned repositories.

Changes:

  • Adds shared directory validation for Upstream and Locator Git fields.
  • Applies validation to fetch and direct cloning entry points.
  • Adds tests for valid paths, traversal attempts, and NUL bytes.
File Description
pkg/​lib/​util/​fetch/​fetch.go Adds directory checks before fetching and cloning.
pkg/​lib/​util/​fetch/​fetch_test.go Tests traversal rejection at fetch and cloning entry points.
api/​kptfile/​v1/​validation.go Implements shared validation and integrates it into metadata checks.
api/​kptfile/​v1/​validation_test.go Tests metadata validation and directory path cases.

Review effort: Balanced

Comment thread api/kptfile/v1/validation.go Resolved
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The path guard allows a symlink ancestor to escape the repository root, enabling fetch/update to copy host files such as those in /etc.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread pkg/lib/util/fetch/fetch.go Resolved
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api bug Something isn't working go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants