Skip to content

fix: improve path validation in Kptfile functionConfig#4470

Open
NETIZEN-11 wants to merge 6 commits intokptdev:mainfrom
NETIZEN-11:fix/validation-path-security
Open

fix: improve path validation in Kptfile functionConfig#4470
NETIZEN-11 wants to merge 6 commits intokptdev:mainfrom
NETIZEN-11:fix/validation-path-security

Conversation

@NETIZEN-11
Copy link
Copy Markdown

Description

This PR improves the path validation logic in validateFnConfigPathSyntax function to ensure consistent behavior across different operating systems and enhance security.

Changes

  • Replace path.IsAbs with filepath.IsAbs for OS-agnostic path validation
  • Clean path before validation using filepath.Clean to normalize path separators
  • Simplify directory traversal check by validating cleaned path for ".."
  • Remove redundant path package import

Motivation

The previous implementation used path.IsAbs which is forward-slash based and may not work correctly on Windows. Using filepath.IsAbs ensures consistent validation across all operating systems.

Cleaning the path before validation also helps normalize different path separator styles and makes the ".." check more reliable.

Security Impact

This change strengthens security by:

  • Preventing directory traversal attacks in functionConfig paths
  • Ensuring absolute paths are correctly rejected regardless of OS
  • Normalizing paths before validation to catch edge cases

Testing

  • Existing tests continue to pass
  • Path validation works correctly on both Unix and Windows systems

Related Issues

Separated from #4432 as suggested by @liamfallon to keep validation changes independent from version-related changes.


NETIZEN-11 and others added 6 commits April 1, 2026 20:48
…nctions

- Upgrade sigs.k8s.io/kustomize/api from v0.20.1 to v0.21.0
- Upgrade sigs.k8s.io/kustomize/kyaml from v0.20.1 to v0.21.0
- Upgrade k8s.io/api from v0.34.1 to v0.35.0
- Upgrade k8s.io/apimachinery from v0.34.1 to v0.35.0
- Upgrade k8s.io/kubectl from v0.34.1 to v0.35.0
- Upgrade github.com/kptdev/krm-functions-catalog/functions/go/apply-setters from v0.2.2 to v0.2.4
- Update catalog function registry to reference new apply-setters version
- Run go mod tidy to resolve transitive dependencies

Resolves GitHub Issue kptdev#4406

All catalog functions remain compatible with new APIs - zero breaking changes encountered.
Zero compilation errors and zero failing tests across repository.

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
…n, and CRLF

- Update testdata Kptfiles to use apply-setters:v0.2.4 (was v0.2.0)
  which is not registered in the functions map, causing TestRender failures
- Fix validateFnConfigPathSyntax to use path.IsAbs (forward-slash) instead
  of filepath.IsAbs so absolute path detection works correctly on all platforms
- Normalize CRLF to LF in pkg_context_test.go when reading expected output
  files to fix TestPkgContextGenerator on Windows
- Remove unused absPath helper and os import from executor_test.go

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
- Remove duplicate entries for apply-setters (v0.2.2) and krm-functions-sdk (v1.0.2)
- Bump k8s.io/apiextensions-apiserver from v0.34.1 to v0.35.0 to align all k8s deps
- Remove gogo/protobuf indirect dep (no longer needed)
- Run go mod tidy to validate

Addresses reviewer feedback on PR kptdev#4432

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
…ility

The PR bumps apply-setters to v0.2.4 in go.mod. Adding v0.2.4 to the
functions registry is required so Kptfiles referencing the new version
work with the built-in runner. v0.2.0 is kept for backward compatibility
with existing Kptfiles that already reference that version.

Also revert testdata Kptfiles back to v0.2.0 since both versions are
now supported by the functions map.

Addresses reviewer question on PR kptdev#4432

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
- Replace path.IsAbs with filepath.IsAbs for consistent OS handling
- Clean path before validation to normalize separators
- Simplify '..' check by cleaning path first
- Remove redundant 'path' package import

This improves security by ensuring path validation works correctly
across different operating systems and prevents directory traversal
attacks in functionConfig paths.

Signed-off-by: NETIZEN-11 <niteshkumar121411@gmail.com>
Copilot AI review requested due to automatic review settings April 7, 2026 19:44
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 7, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 308d6e0
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69d55eb678e331000892f9fb
😎 Deploy Preview https://deploy-preview-4470--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working go Pull requests that update Go code labels Apr 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Kubernetes and kustomize dependencies to newer versions and adds support for the apply-setters v0.2.4 catalog function while maintaining backward compatibility. It also includes bug fixes for test path handling and cross-platform test improvements. However, the PR description claims to include improvements to path validation in the Kptfile functionConfig, but these changes are not present in the provided diffs.

Changes:

  • Fix bugs in executor_test.go where incorrect variable names were used in mkdir operations
  • Add cross-platform path handling to tests using an absPath() helper function
  • Add backward-compatible support for apply-setters v0.2.4 in the function registry while keeping v0.2.0
  • Normalize line endings in pkg_context_test.go for cross-platform test compatibility
  • Update Kubernetes dependencies from v0.34.1 to v0.35.0
  • Update kustomize/api and kyaml from v0.20.1 to v0.21.0
  • Update krm-functions-catalog to v0.2.4 and krm-functions-sdk to v1.0.0

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/util/render/executor_test.go Fixed bugs using wrong variable names in mkdir calls; added absPath() helper for cross-platform path handling
internal/kptops/functions.go Added support for apply-setters v0.2.4 while keeping v0.2.0 for backward compatibility
internal/builtins/pkg_context_test.go Added line ending normalization for cross-platform test comparison
go.mod Updated Kubernetes and kustomize dependencies to newer versions
go.sum Updated checksums for dependency versions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +42 to +43
var rootString = "/root"
var subPkgString = "/root/subpkg"
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.

Why are these vars now?

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.

Are the version changes here beyond apply-setters intentional? Also, definitely don't downgrade the SDK version.

@liamfallon
Copy link
Copy Markdown
Contributor

What's the relationship with PR #4432 ?

@NETIZEN-11
Copy link
Copy Markdown
Author

Hi @liamfallon, PR #4470 is a follow-up to #4432.

#4432 handles the broader dependency upgrades (kyaml, kustomize API, k8s.io, apply-setters). #4470 addresses the reviewer feedback from that PR (duplicate go.mod entries, k8s.io/apiextensions-apiserver alignment, functions registry question) along with an additional fix to validateFnConfigPathSyntax using filepath.IsAbs for correct cross-platform path validation.

Should have referenced this clearly in the PR description — apologies for the confusion. Happy to consolidate if preferred.

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

Labels

bug Something isn't working go Pull requests that update Go code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants