-
Notifications
You must be signed in to change notification settings - Fork 7
fix(middleware): use world-readable permissions for payload files #773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -129,12 +129,12 @@ func savePayload(baseDir, sessionID, queryID string, payload []byte) (string, er | |||||||||||||||||
| logger.LogDebug("payload", "Creating payload directory: baseDir=%s, session=%s, query=%s, fullPath=%s", | ||||||||||||||||||
| baseDir, sessionID, queryID, dir) | ||||||||||||||||||
|
|
||||||||||||||||||
| if err := os.MkdirAll(dir, 0700); err != nil { | ||||||||||||||||||
| if err := os.MkdirAll(dir, 0755); err != nil { | ||||||||||||||||||
| logger.LogError("payload", "Failed to create payload directory: path=%s, error=%v", dir, err) | ||||||||||||||||||
| return "", fmt.Errorf("failed to create payload directory: %w", err) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| logger.LogDebug("payload", "Successfully created payload directory: path=%s, permissions=0700", dir) | ||||||||||||||||||
| logger.LogDebug("payload", "Successfully created payload directory: path=%s, permissions=0755", dir) | ||||||||||||||||||
|
|
||||||||||||||||||
| // Save payload to file with restrictive permissions (owner read/write only) | ||||||||||||||||||
| filePath := filepath.Join(dir, "payload.json") | ||||||||||||||||||
|
|
@@ -143,13 +143,13 @@ func savePayload(baseDir, sessionID, queryID string, payload []byte) (string, er | |||||||||||||||||
| logger.LogInfo("payload", "Writing large payload to filesystem: path=%s, size=%d bytes (%.2f KB, %.2f MB)", | ||||||||||||||||||
| filePath, payloadSize, float64(payloadSize)/1024, float64(payloadSize)/(1024*1024)) | ||||||||||||||||||
|
|
||||||||||||||||||
| if err := os.WriteFile(filePath, payload, 0600); err != nil { | ||||||||||||||||||
| if err := os.WriteFile(filePath, payload, 0644); err != nil { | ||||||||||||||||||
| logger.LogError("payload", "Failed to write payload file: path=%s, size=%d bytes, error=%v", | ||||||||||||||||||
| filePath, payloadSize, err) | ||||||||||||||||||
| return "", fmt.Errorf("failed to write payload file: %w", err) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
| // Ensure file has the expected permissions, even if it already existed | |
| if err := os.Chmod(filePath, 0644); err != nil { | |
| logger.LogError("payload", "Failed to set payload file permissions: path=%s, permissions=%04o, error=%v", | |
| filePath, 0644, err) | |
| return "", fmt.Errorf("failed to set payload file permissions: %w", err) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.MkdirAllonly applies the provided mode when the directory is created; if the directory already exists its permissions are not updated. If this change is intended to make existing payload dirs readable by agents after an upgrade, add an explicitos.Chmod(and potentially for parent/session dirs) to ensure the effective permissions become 0755.This issue also appears on line 132 of the same file.