Skip to content

Add owner-only permission check to manage-gist workflow#42

Merged
caibingcheng merged 3 commits intomasterfrom
copilot/check-approval-for-ci-trigger
Dec 31, 2025
Merged

Add owner-only permission check to manage-gist workflow#42
caibingcheng merged 3 commits intomasterfrom
copilot/check-approval-for-ci-trigger

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 31, 2025

The workflow triggered on any user's issue comments containing ADD/DELETE commands, allowing unauthorized gist modifications.

Changes

  • Workflow condition: Added github.event.comment.user.login == github.repository_owner check to restrict workflow execution to repository owner only
if: |
  github.event.comment.user.login == github.repository_owner &&
  (contains(github.event.comment.body, 'ADD') || 
  contains(github.event.comment.body, 'DELETE'))
  • Documentation: Updated README.md and USAGE_EXAMPLES.md to reflect owner-only access requirement

  • Tests: Added should_trigger_workflow() function with 8 test cases validating permission logic (owner vs non-owner, with/without commands)

Impact

Previously any GitHub user could modify the gist by commenting on issues. Now restricted to repository owner (caibingcheng) only.

Original prompt

检查.github/workflows/manage-gist.yml是否有权限检查, 是否只有我的评论才会触发ci?


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
rssblog Ready Ready Preview, Comment Dec 31, 2025 10:03am

Copilot AI changed the title [WIP] Check CI trigger permissions for comments Add owner-only permission check to manage-gist workflow Dec 31, 2025
Copilot AI requested a review from caibingcheng December 31, 2025 10:05
@caibingcheng caibingcheng marked this pull request as ready for review December 31, 2025 10:07
Copilot AI review requested due to automatic review settings December 31, 2025 10:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a critical security fix to prevent unauthorized gist modifications by restricting workflow execution to the repository owner only. Previously, any GitHub user commenting on issues could trigger gist modifications through ADD/DELETE commands.

Key changes:

  • Added owner-only permission check (github.event.comment.user.login == github.repository_owner) to workflow trigger condition
  • Implemented comprehensive test suite with 8 test cases validating permission logic
  • Updated documentation in README.md and USAGE_EXAMPLES.md to reflect the security enhancement

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/manage-gist.yml Added permission check to workflow condition, restricting execution to repository owner
.github/workflows/test_workflow_logic.py Added should_trigger_workflow() function with test cases for owner/non-owner scenarios
.github/workflows/README.md Documented the new owner-only security requirement
.github/workflows/USAGE_EXAMPLES.md Updated workflow trigger conditions and troubleshooting sections with owner verification details

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

1. A comment is created on an issue
2. The comment contains "ADD " or "DELETE " (with space after the keyword)
2. **The comment author is the repository owner (caibingcheng)**
3. The comment contains "ADD " or "DELETE " (with space after the keyword)
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states "with space after the keyword" but this is misleading. The workflow condition uses contains(github.event.comment.body, 'ADD') which is a simple substring check - it will match "ADD", "ADDON", "ADDED", "BADDER", etc. The actual filtering happens later via regex pattern ADD\s+(\S+)\s+(\S+) in the Python script (lines 149-150 in manage-gist.yml), which requires whitespace. The documentation should clarify that the workflow trigger is broad (substring match) but only properly formatted commands with spaces will be processed successfully.

Copilot uses AI. Check for mistakes.

- The workflow triggers on issue comments (when a comment is created)
- **Security**: It only runs if the comment author is the repository owner (caibingcheng)
- It only runs if the comment contains "ADD " or "DELETE " commands
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation claims commands require "ADD " or "DELETE " with a space, but this contradicts the actual workflow behavior. The workflow's contains() function performs a simple substring check and will trigger on words like "ADDON", "BADDER", "DELETES", etc. While the Python script's regex later filters to proper format, the workflow will still run (and waste CI resources) on false matches. Consider either updating the documentation to accurately describe this two-stage filtering, or improving the workflow condition to be more precise (e.g., using regex in the workflow condition itself).

Suggested change
- It only runs if the comment contains "ADD " or "DELETE " commands
- It triggers when the comment text contains the substrings "ADD" or "DELETE" (simple substring match), and the Python script then processes only comments that contain properly formatted `ADD <section> <URL>` or `DELETE <section> <URL>` commands

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +91
test_cases = [
# (comment_author, comment_body, should_trigger, description)
("caibingcheng", "ADD friends https://example.com/feed.xml", True, "Owner with ADD command"),
("caibingcheng", "DELETE friends https://example.com/feed.xml", True, "Owner with DELETE command"),
("caibingcheng", "Just a regular comment", False, "Owner without command"),
("other-user", "ADD friends https://example.com/feed.xml", False, "Non-owner with ADD command"),
("other-user", "DELETE friends https://example.com/feed.xml", False, "Non-owner with DELETE command"),
("other-user", "Just a regular comment", False, "Non-owner without command"),
("caibingcheng", "Please ADD tech https://tech.example.com/rss", True, "Owner with ADD in sentence"),
("random-user", "Can you DELETE blog https://blog.example.com/atom.xml", False, "Non-owner with DELETE in sentence"),
]
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test cases don't verify the actual behavior of the workflow condition. The workflow uses contains() which is a substring match, meaning comments like "ADDON friends url" or "BADDER text" would trigger the workflow (though they'd fail during parsing). Consider adding test cases for edge cases like "ADDON", "ADDED", "BADDER", "DELETES", etc. to demonstrate this behavior and align with the actual workflow logic. This would help document the two-stage filtering: workflow trigger (broad substring match) vs. command parsing (strict regex).

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +17
github.event.comment.user.login == github.repository_owner &&
(contains(github.event.comment.body, 'ADD') ||
contains(github.event.comment.body, 'DELETE'))
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions' contains() function is case-sensitive, meaning lowercase commands like "add friends url" or "delete friends url" will not trigger the workflow. Consider documenting this behavior in the troubleshooting section, or add a case-insensitive check in the workflow condition. For example: contains(github.event.comment.body, 'ADD') || contains(github.event.comment.body, 'add') or convert to uppercase before checking. This would improve user experience and prevent confusion when commands don't trigger.

Copilot uses AI. Check for mistakes.
@caibingcheng caibingcheng merged commit 6e6e572 into master Dec 31, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants