Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Jan 5, 2026

Security Fix: Incorrect Default Permissions in File Tracker

Alert Number: #378
Severity: Medium
Rule: G306 - Expect WriteFile permissions to be 0600 or less
File: pkg/cli/file_tracker.go:158

Vulnerability Description

The security scanner identified that files being restored during rollback operations were written with overly permissive permissions (0644). This violates the principle of least privilege and could expose file contents to unauthorized users on shared systems.

With 0644 permissions (rw-r--r--), files are:

  • Readable and writable by the owner
  • Readable by the group
  • Readable by all other users

This is unnecessary for workflow files that should only be accessible to the owner.

Fix Applied

Changed file permissions from 0644 to 0600 in the RollbackModifiedFiles function at line 159.

Before:

// Restore original content if we have it
if originalContent, exists := ft.OriginalContent[file]; exists {
    if err := os.WriteFile(file, originalContent, 0644); err != nil {
        errors = append(errors, fmt.Sprintf("failed to restore %s: %v", file, err))
    }
}

After:

// Restore original content if we have it
if originalContent, exists := ft.OriginalContent[file]; exists {
    // Use owner-only read/write permissions (0600) for security best practices
    if err := os.WriteFile(file, originalContent, 0600); err != nil {
        errors = append(errors, fmt.Sprintf("failed to restore %s: %v", file, err))
    }
}

With 0600 permissions (rw-------), files are:

  • Readable and writable by the owner only
  • Not accessible to group or other users

Security Best Practices Applied

  • Principle of Least Privilege: Files created with the minimum necessary permissions
  • Defense in Depth: Even if directory permissions are permissive, individual files remain protected
  • Secure by Default: Restored files are private by default
  • CWE-732 Prevention: Prevents "Incorrect Permission Assignment for Critical Resource"

Files Affected

This fix applies to:

  • Workflow files restored during rollback operations in the FileTracker component

Testing

  • ✅ Build succeeded: go build ./pkg/cli/...
  • ✅ No breaking changes: Functionality remains identical
  • ✅ Permissions are applied at file write time
  • ✅ Rollback operations continue to work correctly

Impact Assessment

Risk: Low
Breaking Changes: None
Backwards Compatibility: Full
Performance: No impact

Files restored during rollback operations remain fully functional with more restrictive permissions. The rollback functionality is performed by the same user who created the files, so the tighter permissions do not affect functionality.

References


🤖 Generated by Security Fix Agent in workflow run 20701728409

AI generated by Security Fix PR

- Changed file permissions from 0644 to 0600 in RollbackModifiedFiles
- Files restored during rollback now have owner-only read/write permissions
- Follows security best practices and principle of least privilege
- Fixes gosec alert #378 (G306 - Expect WriteFile permissions to be 0600 or less)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@pelikhan pelikhan marked this pull request as ready for review January 5, 2026 00:49
@pelikhan pelikhan merged commit 925475d into main Jan 5, 2026
3 checks passed
@pelikhan pelikhan deleted the main-8379eb1629300f23 branch January 5, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant