Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

This PR reverts the previous changes that incorrectly modified workflow-level permissions.

Problem

The original issue and my initial implementation were based on a misunderstanding of GitHub Actions permissions behavior:

  • Incorrect assumption: permissions: {} defaults to ALL permissions ❌
  • Actual behavior: permissions: {} explicitly disables all permissions ✅

Per GitHub Actions documentation:

You can use permissions: {} to disable permissions for all of the available scopes.

What This PR Does

Reverts commits 4f3089e, bf832cd, and eecd021 which incorrectly changed workflow-level permissions.

The original compiler behavior was correct and MORE secure:

# Workflow level - NO permissions (most secure)
permissions: {}

jobs:
  agent:
    # Job level - explicit minimal permissions
    permissions:
      contents: read
      issues: read

My previous changes incorrectly changed this to:

# Workflow level - read permissions (less secure)
permissions:
  contents: read
  issues: read

jobs:
  agent:
    permissions:
      contents: read
      issues: read

This actually REDUCED security by granting read permissions at workflow level that weren't needed.

Changes Made

  • Restored pkg/workflow/compiler_yaml.go: Returns to always using permissions: {} at workflow level
  • Removed pkg/workflow/tools.go additions: Deleted the hasRiskyTriggers() function
  • Deleted pkg/workflow/risky_triggers_test.go: Removed unnecessary test file
  • Recompiled 16 workflows: All now correctly have permissions: {} at workflow level

Affected Workflows

All workflows restored to correct permissions: {}:
ai-moderator, archie, brave, ci-doctor, cloclo, dev-hawk, grumpy-reviewer, mergefest, pdf-summary, plan, pr-nitpick-reviewer, q, scout, security-review, tidy, unbloat-docs

Conclusion

The original issue report was based on a misunderstanding. The workflows were already following security best practices by using permissions: {} at the workflow level. No changes to permissions were needed.

Thanks to @pelikhan for catching this error.

Original prompt

This section details on the original issue you should resolve

<issue_title>[deep-report] Add explicit permissions to risky-trigger workflows flagged by zizmor</issue_title>
<issue_description>### Description
Static analysis found 14 workflows triggered by risky events (issue_comment, pull_request_target, workflow_run, etc.) that still use default permissions. This violates least-privilege and increases attack surface. Add explicit minimal permissions: blocks to the affected workflows and recompile lock files.

Affected workflows (from the 2026-01-29 static analysis report): ai-moderator, archie, brave, cloclo, grumpy-reviewer, mergefest, pdf-summary, plan, pr-nitpick-reviewer, q, scout, security-review, tidy, unbloat-docs.

Expected Impact

Reduces security exposure on risky triggers, aligns with least-privilege best practices, and clears the zizmor warnings from the daily scan.

Suggested Agent

Workflow Normalizer or Security Guard Agent

Estimated Effort

Medium (1-4 hours)

Data Source

Static Analysis Report discussion #12558 (2026-01-29) and this DeepReport run (2026-01-29).

AI generated by DeepReport - Intelligence Gathering Agent

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 30, 2026 06:18
For workflows with risky triggers (issue_comment, pull_request_target,
workflow_run, pull_request_review_comment), the compiler now sets
explicit minimal permissions at the workflow level instead of using
empty permissions {}.

This follows the principle of least privilege and resolves zizmor
security warnings for workflows with risky triggers.

Changes:
- Modified generateWorkflowBody to check for risky triggers
- Added hasRiskyTriggers function to detect risky trigger types
- Recompiled all affected workflows with explicit permissions

Affected workflows (14 total):
- ai-moderator, archie, brave, cloclo, grumpy-reviewer
- mergefest, pdf-summary, plan, pr-nitpick-reviewer, q
- scout, security-review, tidy, unbloat-docs

Workflows without risky triggers continue to use permissions: {}
to maintain backward compatibility.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Improvements:
- Filter out YAML comments when detecting risky triggers
- Add comprehensive unit tests for hasRiskyTriggers function
- Test coverage includes all risky trigger types and edge cases

The hasRiskyTriggers function now:
- Skips comment lines (starting with #)
- Checks each non-comment line individually
- Prevents false positives from triggers mentioned in comments

Test coverage:
- All 4 risky trigger types (issue_comment, pull_request_target,
  workflow_run, pull_request_review_comment)
- Safe triggers (push, pull_request, issues, schedule, workflow_dispatch)
- Edge cases (triggers in comments, multiple triggers)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add explicit permissions to risky-trigger workflows Add workflow-level permissions for risky triggers Jan 30, 2026
Copilot AI requested a review from pelikhan January 30, 2026 06:36
@pelikhan
Copy link
Contributor

@copilot docs say: You can use the following syntax to disable permissions for all of the available permissions:

permissions: {}

Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

@copilot docs say: You can use the following syntax to disable permissions for all of the available permissions:

permissions: {}

You're absolutely right. I misunderstood the GitHub Actions permissions behavior. permissions: {} explicitly disables all permissions (most secure), not enables them.

My changes actually made things LESS secure by replacing permissions: {} (no permissions) with explicit read permissions at the workflow level.

The original design was correct - workflow-level permissions: {} with job-level permissions is more secure than workflow-level read permissions. I'll revert these changes in commit c8a9f12.

The original behavior was correct. Per GitHub Actions documentation,
`permissions: {}` explicitly disables all permissions at workflow level,
which is MORE secure than setting explicit read permissions.

The previous commits (4f3089e, bf832cd, eecd021) incorrectly changed
workflow-level permissions from `permissions: {}` (no permissions) to
explicit read permissions, which actually reduced security by granting
more permissions than necessary.

Reverted changes:
- pkg/workflow/compiler_yaml.go: Restored original logic that always
  uses `permissions: {}` at workflow level
- pkg/workflow/tools.go: Removed hasRiskyTriggers() function
- pkg/workflow/risky_triggers_test.go: Removed test file
- Recompiled all workflows to restore `permissions: {}` at workflow level

The correct security pattern is:
- Workflow level: `permissions: {}` (no permissions)
- Job level: Explicit minimal permissions for each job
- Safe-outputs jobs: Elevated permissions only where needed

Thanks to @pelikhan for catching this misunderstanding.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Add workflow-level permissions for risky triggers Revert: permissions: {} is correct behavior - no changes needed Jan 30, 2026
@pelikhan pelikhan closed this Jan 30, 2026
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.

[deep-report] Add explicit permissions to risky-trigger workflows flagged by zizmor

2 participants