1
---
2
name: secret-scanning
3
description: 'Guide for configuring and managing GitHub secret scanning, push protection, custom patterns, and secret alert remediation. For pre-commit secret scanning in AI coding agents via the GitHub MCP Server, this skill references the Advanced Security plugin (`advanced-security@copilot-plugins`). Use this skill when enabling secret scanning, setting up push protection, defining custom patterns, triaging alerts, resolving blocked pushes, or when an agent needs to scan code for secrets before committing.'
4
---
5
6
# Secret Scanning
7
8
This skill provides procedural guidance for configuring GitHub secret scanning — detecting leaked credentials, preventing secret pushes, defining custom patterns, and managing alerts.
9
10
## When to Use This Skill
11
12
Use this skill when the request involves:
13
14
- Enabling or configuring secret scanning for a repository or organization
15
- Setting up push protection to block secrets before they reach the repository
16
- Defining custom secret patterns with regular expressions
17
- Resolving a blocked push from the command line
18
- Triaging, dismissing, or remediating secret scanning alerts
19
- Configuring delegated bypass for push protection
20
- Excluding directories from secret scanning via `secret_scanning.yml`
21
- Understanding alert types (user, partner, push protection)
22
- Enabling validity checks or extended metadata checks
23
- Scanning local code changes for secrets before committing (via MCP / AI coding agent) — see the **Pre-Commit Scanning via AI Coding Agents** section below for the recommended plugin
24
25
## How Secret Scanning Works
26
27
Secret scanning automatically detects exposed credentials across:
28
29
- Entire Git history on all branches
30
- Issue descriptions, comments, and titles (open and closed)
31
- Pull request titles, descriptions, and comments
32
- GitHub Discussions titles, descriptions, and comments
33
- Wikis and secret gists
34
35
### Availability
36
37
| Repository Type | Availability |
38
|---|---|
39
| Public repos | Automatic, free |
40
| Private/internal (org-owned) | Requires GitHub Secret Protection on Team/Enterprise Cloud |
41
| User-owned | Enterprise Cloud with Enterprise Managed Users |
42
43
## Core Workflow — Enable Secret Scanning
44
45
### Step 1: Enable Secret Protection
46
47
1. Navigate to repository **Settings** → **Advanced Security**
48
2. Click **Enable** next to "Secret Protection"
49
3. Confirm by clicking **Enable Secret Protection**
50
51
For organizations, use security configurations to enable at scale:
52
- Settings → Advanced Security → Global settings → Security configurations
53
54
### Step 2: Enable Push Protection
55
56
Push protection blocks secrets during the push process — before they reach the repository.
57
58
1. Navigate to repository **Settings** → **Advanced Security**
59
2. Enable "Push protection" under Secret Protection
60
61
Push protection blocks secrets in:
62
- Command line pushes
63
- GitHub UI commits
64
- File uploads
65
- REST API requests
66
- REST API content creation endpoints
67
68
### Step 3: Configure Exclusions (Optional)
69
70
Create `.github/secret_scanning.yml` to auto-close alerts for specific directories:
71
72
```yaml
73
paths-ignore:
74
- "docs/**"
75
- "test/fixtures/**"
76
- "**/*.example"
77
```
78
79
**Limits:**
80
- Maximum 1,000 entries in `paths-ignore`
81
- File must be under 1 MB
82
- Excluded paths also skip push protection checks
83
84
**Best practices:**
85
- Be as specific as possible with exclusion paths
86
- Add comments explaining why each path is excluded
87
- Review exclusions periodically — remove stale entries
88
- Inform the security team about exclusions
89
90
### Step 4: Enable Additional Features (Optional)
91
92
**Non-provider patterns** — detect private keys, connection strings, generic API keys:
93
- Settings → Advanced Security → enable "Scan for non-provider patterns"
94
95
**AI-powered generic secret detection** — uses Copilot to detect unstructured secrets like passwords:
96
- Settings → Advanced Security → enable "Use AI detection"
97
98
**Validity checks** — verify if detected secrets are still active:
99
- Settings → Advanced Security → enable "Validity checks"
100
- GitHub periodically tests detected credentials against provider APIs
101
- Status shown in alert: `active`, `inactive`, or `unknown`
102
103
**Extended metadata checks** — additional context about who owns a secret:
104
- Requires validity checks to be enabled first
105
- Helps prioritize remediation and identify responsible teams
106
107
## Core Workflow — Resolve Blocked Pushes
108
109
When push protection blocks a push from the command line:
110
111
### Option A: Remove the Secret
112
113
**If the secret is in the latest commit:**
114
```bash
115
# Remove the secret from the file
116
# Then amend the commit
117
git commit --amend --all
118
git push
119
```
120
121
**If the secret is in an earlier commit:**
122
```bash
123
# Find the earliest commit containing the secret
124
git log
125
126
# Start interactive rebase before that commit
127
git rebase -i <COMMIT-ID>~1
128
129
# Change 'pick' to 'edit' for the offending commit
130
# Remove the secret, then:
131
git add .
132
git commit --amend
133
git rebase --continue
134
git push
135
```
136
137
### Option B: Bypass Push Protection
138
139
1. Visit the URL returned in the push error message (as the same user)
140
2. Select a bypass reason:
141
- **It's used in tests** — alert created and auto-closed
142
- **It's a false positive** — alert created and auto-closed
143
- **I'll fix it later** — open alert created
144
3. Click **Allow me to push this secret**
145
4. Re-push within 3 hours
146
147
### Option C: Request Bypass Privileges
148
149
If delegated bypass is enabled and you lack bypass privileges:
150
1. Visit the URL from the push error
151
2. Add a comment explaining why the secret is safe
152
3. Click **Submit request**
153
4. Wait for email notification of approval/denial
154
5. If approved, push the commit; if denied, remove the secret
155
156
> For detailed bypass and delegated bypass workflows, search `references/push-protection.md`.
157
158
## Custom Patterns
159
160
Define organization-specific secret patterns using regular expressions.
161
162
### Quick Setup
163
164
1. Settings → Advanced Security → Custom patterns → **New pattern**
165
2. Enter pattern name and regex for secret format
166
3. Add a sample test string
167
4. Click **Save and dry run** to test (up to 1,000 results)
168
5. Review results for false positives
169
6. Click **Publish pattern**
170
7. Optionally enable push protection for the pattern
171
172
### Scopes
173
174
Custom patterns can be defined at:
175
- **Repository level** — applies to that repo only
176
- **Organization level** — applies to all repos with secret scanning enabled
177
- **Enterprise level** — applies across all organizations
178
179
### Copilot-Assisted Pattern Generation
180
181
Use Copilot secret scanning to generate regex from a text description of the secret type, including optional example strings.
182
183
> For detailed custom pattern configuration, search `references/custom-patterns.md`.
184
185
## Alert Management
186
187
### Alert Types
188
189
| Type | Description | Visibility |
190
|---|---|---|
191
| **User alerts** | Secrets found in repository | Security tab |
192
| **Push protection alerts** | Secrets pushed via bypass | Security tab (filter: `bypassed: true`) |
193
| **Partner alerts** | Secrets reported to provider | Not shown in repo (provider-only) |
194
195
### Alert Lists
196
197
- **Default alerts** — supported provider patterns and custom patterns
198
- **Generic alerts** — non-provider patterns and AI-detected secrets (limited to 5,000 per repo)
199
200
### Remediation Priority
201
202
1. **Rotate the credential immediately** — this is the critical action
203
2. Review the alert for context (location, commit, author)
204
3. Check validity status: `active` (urgent), `inactive` (lower priority), `unknown`
205
4. Remove from Git history if needed (time-intensive, often unnecessary after rotation)
206
207
### Dismissing Alerts
208
209
Dismiss with a documented reason:
210
- **False positive** — detected string is not a real secret
211
- **Revoked** — credential has already been revoked
212
- **Used in tests** — secret is only in test code
213
214
> For detailed alert types, validity checks, and REST API, search `references/alerts-and-remediation.md`.
215
216
## Pre-Commit Scanning via AI Coding Agents
217
218
For scanning code changes for secrets inside an AI coding agent before committing, install the **Advanced Security plugin** which provides the `run_secret_scanning` MCP tool and a dedicated scanning skill.
219
220
**GitHub Copilot CLI:**
221
```bash
222
/plugin install advanced-security@copilot-plugins
223
```
224
225
**Visual Studio Code:**
226
- In Copilot Chat, open **Chat: Plugins** (or use `@agentPlugins`) and install the `advanced-security` plugin
227
- Then run `/secret-scanning` in Copilot Chat
228
229
See: [Advanced Security Plugin — Secret Scanning Skill](https://github.com/github/copilot-plugins/blob/main/plugins/advanced-security/skills/secret-scanning/SKILL.md)
230
231
> Announced in [Secret scanning in AI coding agents via the GitHub MCP Server](https://github.blog/changelog/2026-03-17-secret-scanning-in-ai-coding-agents-via-the-github-mcp-server/) (March 2026)
232
233
## Reference Files
234
235
For detailed documentation, load the following reference files as needed:
236
237
- `references/push-protection.md` — Push protection mechanics, bypass workflow, delegated bypass, user push protection
238
- Search patterns: `bypass`, `delegated`, `bypass request`, `command line`, `REST API`, `user push protection`
239
- `references/custom-patterns.md` — Custom pattern creation, regex syntax, dry runs, Copilot regex generation, scopes
240
- Search patterns: `custom pattern`, `regex`, `dry run`, `publish`, `organization`, `enterprise`, `Copilot`
241
- `references/alerts-and-remediation.md` — Alert types, validity checks, extended metadata, generic alerts, secret removal, REST API
242
- Search patterns: `user alert`, `partner alert`, `validity`, `metadata`, `generic`, `remediation`, `git history`, `REST API`
243