Skip to content

Commit b8ac1be

Browse files
committed
fix(feat): Prevent Path Traversal in Archive Extraction and Escape Injection in String Construction
Signed-off-by: Jörmungandrk <github@zerodaysec.org>
1 parent fdc0786 commit b8ac1be

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

cilium-cli/connectivity/check/deployment.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,10 +1900,17 @@ func (ct *ConnectivityTest) deployPerf(ctx context.Context) error {
19001900
var lowPrioDeployAnnotations = annotations{bwPrioAnnotationString: "5"}
19011901
var highPrioDeployAnnotations = annotations{bwPrioAnnotationString: "6"}
19021902

1903-
ct.params.DeploymentAnnotations.Set(`{
1904-
"` + perClientLowPriorityDeploymentName + `": ` + lowPrioDeployAnnotations.String() + `,
1905-
"` + perClientHighPriorityDeploymentName + `": ` + highPrioDeployAnnotations.String() + `
1906-
}`)
1903+
deployAnnos := map[string]annotations{
1904+
perClientLowPriorityDeploymentName: lowPrioDeployAnnotations,
1905+
perClientHighPriorityDeploymentName: highPrioDeployAnnotations,
1906+
}
1907+
if jsonBytes, err := json.Marshal(deployAnnos); err != nil {
1908+
ct.Warnf("failed to marshal deployment annotations: %s", err)
1909+
} else {
1910+
if err := ct.params.DeploymentAnnotations.Set(string(jsonBytes)); err != nil {
1911+
ct.Warnf("failed to set deployment annotations: %s", err)
1912+
}
1913+
}
19071914
if err = ct.createServerPerfDeployment(ctx, perfServerDeploymentName, serverNode.Name, false); err != nil {
19081915
ct.Warnf("unable to create deployment: %s", err)
19091916
}

cilium-cli/sysdump/sysdump.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,23 @@ func untar(src string, dst string) error {
23432343
if err != nil {
23442344
return err
23452345
}
2346-
filename := filepath.Join(dst, name)
2346+
cleanName := filepath.Clean(name)
2347+
// Security: Prevent Zip Slip (directory traversal)
2348+
if cleanName == "." || strings.HasPrefix(cleanName, "..") || filepath.IsAbs(cleanName) || strings.Contains(cleanName, "../") || strings.Contains(cleanName, `..\`) {
2349+
return fmt.Errorf("tar entry %q resolves outside of target dir", header.Name)
2350+
}
2351+
filename := filepath.Join(dst, cleanName)
2352+
absDst, err := filepath.Abs(dst)
2353+
if err != nil {
2354+
return err
2355+
}
2356+
absFile, err := filepath.Abs(filename)
2357+
if err != nil {
2358+
return err
2359+
}
2360+
if !strings.HasPrefix(absFile, absDst+string(os.PathSeparator)) && absFile != absDst {
2361+
return fmt.Errorf("tar entry %q would be extracted outside of target dir", header.Name)
2362+
}
23472363
directory := filepath.Dir(filename)
23482364
if err := os.MkdirAll(directory, 0755); err != nil {
23492365
return err

pkg/policy/l4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ func (sp *PerSelectorPolicy) redirectType() redirectTypes {
12071207
func (l4 *L4Filter) Marshal() string {
12081208
b, err := json.Marshal(l4)
12091209
if err != nil {
1210-
b = []byte("\"L4Filter error: " + err.Error() + "\"")
1210+
b = []byte(strconv.Quote("L4Filter error: " + err.Error()))
12111211
}
12121212
return string(b)
12131213
}

0 commit comments

Comments
 (0)