Skip to content

Commit f8a84b0

Browse files
authored
mandatory authorization check to prevent external contributors from triggering AI agent (#23)
1 parent 30f077f commit f8a84b0

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

action.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,36 @@ runs:
141141
echo "::debug::mcp-gateway install: $MCP_GATEWAY"
142142
fi
143143
144+
# ========================================
145+
# SECURITY: Authorization Check
146+
# Only enforced for comment-triggered events (the main abuse vector)
147+
# PR-triggered workflows are controlled by the workflow author
148+
# ========================================
149+
- name: Check authorization
150+
id: check-auth
151+
shell: bash
152+
env:
153+
ACTION_PATH: ${{ github.action_path }}
154+
# Get author_association from comment events (the main risk)
155+
COMMENT_ASSOCIATION: ${{ github.event.comment.author_association }}
156+
DEBUG: ${{ inputs.debug }}
157+
run: |
158+
# Only enforce auth for comment-triggered events
159+
# This prevents abuse via /commands while allowing PR-triggered workflows to run
160+
if [ -z "$COMMENT_ASSOCIATION" ]; then
161+
echo "ℹ️ Skipping auth check (not a comment-triggered event)"
162+
echo "authorized=skipped" >> $GITHUB_OUTPUT
163+
exit 0
164+
fi
165+
166+
echo "Using comment author_association: $COMMENT_ASSOCIATION"
167+
168+
# Allowed roles (hardcoded for security - cannot be overridden)
169+
ALLOWED_ROLES='["OWNER", "MEMBER", "COLLABORATOR"]'
170+
171+
# Run the authorization check
172+
$ACTION_PATH/security/check-auth.sh "$COMMENT_ASSOCIATION" "$ALLOWED_ROLES"
173+
144174
# ========================================
145175
# SECURITY: Sanitize and Analyze Input
146176
# ========================================

security/README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ This directory contains security hardening scripts for the cagent-action GitHub
66

77
This action includes **built-in security features for all agent executions**:
88

9-
1. **Output Scanning** - All agent responses are scanned for leaked secrets:
9+
1. **Authorization Check** - Users are verified for comment-triggered events:
10+
- Only `OWNER`, `MEMBER`, and `COLLABORATOR` roles can trigger via comments (e.g., `/review`)
11+
- External contributors (`CONTRIBUTOR`, `FIRST_TIME_CONTRIBUTOR`, `NONE`) are blocked
12+
- Skips for non-comment events (PR triggers, scheduled jobs, workflow_dispatch)
13+
- Comment-triggered actions are the main abuse vector - this protects against cost/spam attacks
14+
15+
2. **Output Scanning** - All agent responses are scanned for leaked secrets:
1016

1117
- API key patterns: `sk-ant-*`, `sk-*`, `sk-proj-*`
1218
- GitHub tokens: `ghp_*`, `gho_*`, `ghu_*`, `ghs_*`, `github_pat_*`
1319
- Environment variable names in output
1420
- If secrets detected: workflow fails, security issue created
1521

16-
2. **Prompt Sanitization** - User prompts are checked for:
22+
3. **Prompt Sanitization** - User prompts are checked for:
1723
- Prompt injection patterns ("ignore previous instructions", etc.)
1824
- Requests for API keys or environment variables
1925
- Encoded content (base64, hex) that could hide malicious requests
@@ -25,28 +31,35 @@ The action implements a defense-in-depth approach:
2531

2632
```
2733
┌─────────────────────────────────────────────────────────────┐
28-
│ 1. Prompt Sanitization │
34+
│ 1. Authorization Check (check-auth.sh) │
35+
│ ✓ Verify user's author_association role │
36+
│ ✓ Block external contributors by default │
37+
│ ✓ Only OWNER, MEMBER, COLLABORATOR allowed │
38+
└─────────────────────────────────────────────────────────────┘
39+
40+
┌─────────────────────────────────────────────────────────────┐
41+
│ 2. Prompt Sanitization │
2942
│ ✓ Detect prompt injection attempts │
3043
│ ✓ Warn about suspicious patterns │
3144
│ ✓ Check for encoded malicious content │
3245
└─────────────────────────────────────────────────────────────┘
3346
3447
┌─────────────────────────────────────────────────────────────┐
35-
2. Agent Execution │
48+
3. Agent Execution │
3649
│ ✓ User-provided agent runs in isolated cagent runtime │
3750
│ ✓ No direct access to secrets or environment vars │
3851
│ ✓ Controlled execution environment │
3952
└─────────────────────────────────────────────────────────────┘
4053
4154
┌─────────────────────────────────────────────────────────────┐
42-
3. Output Scanning │
55+
4. Output Scanning │
4356
│ ✓ Scan for leaked API keys (Anthropic, OpenAI, etc.) │
4457
│ ✓ Scan for leaked tokens (GitHub PAT, OAuth, etc.) │
4558
│ ✓ Block execution if secrets found │
4659
└─────────────────────────────────────────────────────────────┘
4760
4861
┌─────────────────────────────────────────────────────────────┐
49-
4. Incident Response │
62+
5. Incident Response │
5063
│ ✓ Create security issue with details │
5164
│ ✓ Fail workflow with clear error │
5265
│ ✓ Prevent secret exposure in logs │

0 commit comments

Comments
 (0)