Fix/mend sca 202609 - #343
Merged
Merged
Conversation
* fix(CLDYCON-7678): guard against path traversal in metric sample dir to fix Mend SAST vulnerability CWE-22 Path/Directory Traversal. * fix(CLDYCON-7678): expand path traversal guards in kubernetes to remediate CWE-73 File Manipulation vulnerability. * Address PR comments: fix safeJoin to allow base-equal paths and update linter config; update correspondant tests. * refactor(CLDYCON-7678): simplify type assertions and fix linter warnings * refactor(CLDYCON-7678): move safeJoin to util and simplify assertions * chore(CLDYCON-7678): migrate golangci-lint config to v2 format and bump to v2.7.2 to match other repos of Containers team.
hunterwei-ibm
force-pushed
the
fix/mend-sca-202609
branch
from
September 25, 2026 18:40
b3ed439 to
9162b34
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR bumps the metrics-agent to version 2.14.17 and includes a set of security hardening, code quality, and dependency update changes:
util.SafeJoinhelper that validates joined file paths remain within the intended base directory, guarding against path traversal attacks. This is applied throughoutkubernetes.go,util.go, and related files wherever paths were previously constructed via raw string concatenation (e.g.,dir + "/" + file).github.com/aws/aws-sdk-go:v1.40.27→v1.55.8github.com/pelletier/go-toml/v2:v2.0.5→v2.4.3golang.org/x/net:v0.53.0→v0.56.0golang.org/x/sys:v0.45.0→v0.46.0golang.org/x/term:v0.43.0→v0.44.0replacedirectives ingo.mod(e.g., forgolang.org/x/crypto,golang.org/x/net,google.golang.org/grpc,google.golang.org/protobuf,github.com/mattn/go-sqlite3) since the direct dependency versions now satisfy the CVE requirements.3.24.1→3.24.2and adds--no-cachetoapk addcommands to reduce image size and avoid stale cache issues.to.(*corev1.Pod)) with the two-value form (cast, _ := to.(*corev1.Pod)) throughoutk8s_stats.goandraw_endpoint.go.switch to := to.(type)) to eliminate redundant casts insanitizeDataandtrimData.ObjectMeta.Xfield access to the promoted field shorthand (e.g.,cast.ObjectMeta.ManagedFields→cast.ManagedFields).defer resp.Body.Close()→defer func() { _ = resp.Body.Close() }(),os.RemoveAll,os.Remove).!(>= 200 && <= 299)to< 200 || > 299.f.WriteString(fmt.Sprintf(...))withfmt.Fprintf(f, ...).n.ObjectMeta.Labels→n.Labels._ "strconv"import.v1.64.2(build by Go 1.24) tov2.7.2due to v1.64.2 incompatibility to Go 1.25.Where should the reviewer start?
util/util.go— Review the newSafeJoinfunction, which is the core security change in this PR.kubernetes/kubernetes.go— Review all call sites whereSafeJoinreplaces raw path concatenation (createMSD,fetchNodeBaselines,updateNodeBaselines,createAgentStatusMetric,fetchDiagnostics).go.mod— Review the dependency upgrades and removedreplacedirectives to confirm no regressions are introduced.retrieval/k8s/k8s_stats.goandretrieval/raw/raw_endpoint.go— Review the type assertion andObjectMetasimplifications for correctness.How should this be manually tested?
go build ./... go test ./...docker build -f deploy/docker/Dockerfile .version: 2.14.16) to a test Kubernetes cluster and confirm the agent pod starts, collects metrics, and exports data without errors.TestSafeJoinunit tests to confirm traversal attempts (e.g.,../../etc/passwd) are correctly rejected.Any background context you want to provide?
replacedirectives ingo.modwere previously needed to pin vulnerable transitive dependency versions (e.g.,golang.org/x/netfor CVE-2026-39821). The direct dependency upgrades in this PR bring in versions that already satisfy those requirements, so the overrides are no longer needed and have been removed to reduce maintenance overhead.SafeJoinutility is being introduced proactively to harden all file path construction in the agent against potential path traversal, which is a common vulnerability class in agents that write files based on cluster-derived data (e.g., node names, timestamps).--no-cacheflag added toapk addin the Dockerfile is a Docker best practice that avoids caching package index files in the image layer, reducing the final image size.What picture best describes this PR (optional but encouraged)?
security hardening + dependency updates keeping the house in order.
What are the relevant Github Issues?
No specific GitHub issues were referenced in the diff. Link any relevant CVE tracking issues or dependency audit tickets here.
Developer Done List
TestSafeJointests inutil/util_test.goTestCreateMSD,TestFetchNodeBaselines,TestUpdateNodeBaselinestests inkubernetes/kubernetes_test.goSafeJoindirectly addresses path traversal; dependency upgrades address known CVEsFor the Reviewer:
SafeJoinimplementation and its call sites to ensure no valid path construction is accidentally rejected (e.g., paths derived from timestamps or UIDs).go.modreplacedirectives forgolang.org/x/net,google.golang.org/grpc, etc. does not reintroduce vulnerable transitive versions — rungo mod graphorgovulncheckif in doubt.cast, _ := to.(Type)) silently ignores assertion failures. Verify this is safe given the call sites always pass the correct concrete types.By approving this PR, the reviewer acknowledges that they have checked all items in this done list.
Reviewer/Approval Done List