ace-git-secrets 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.ace-defaults/git-secrets/config.yml +63 -0
  3. data/.ace-defaults/git-secrets/gitleaks.toml +14 -0
  4. data/.ace-defaults/nav/protocols/guide-sources/ace-git-secrets.yml +10 -0
  5. data/.ace-defaults/nav/protocols/wfi-sources/ace-git-secrets.yml +19 -0
  6. data/CHANGELOG.md +298 -0
  7. data/LICENSE +21 -0
  8. data/README.md +40 -0
  9. data/Rakefile +16 -0
  10. data/docs/demo/ace-git-secrets-getting-started.gif +0 -0
  11. data/docs/demo/ace-git-secrets-getting-started.tape.yml +38 -0
  12. data/docs/demo/fixtures/README.md +3 -0
  13. data/docs/demo/fixtures/sample.txt +1 -0
  14. data/docs/getting-started.md +109 -0
  15. data/docs/handbook.md +43 -0
  16. data/docs/usage.md +301 -0
  17. data/exe/ace-git-secrets +19 -0
  18. data/handbook/agents/security-audit.ag.md +237 -0
  19. data/handbook/guides/security/ruby.md +27 -0
  20. data/handbook/guides/security/rust.md +51 -0
  21. data/handbook/guides/security/typescript.md +33 -0
  22. data/handbook/guides/security.g.md +155 -0
  23. data/handbook/skills/as-git-security-audit/SKILL.md +29 -0
  24. data/handbook/skills/as-git-token-remediation/SKILL.md +21 -0
  25. data/handbook/workflow-instructions/git/security-audit.wf.md +247 -0
  26. data/handbook/workflow-instructions/git/token-remediation.wf.md +294 -0
  27. data/lib/ace/git/secrets/atoms/gitleaks_runner.rb +244 -0
  28. data/lib/ace/git/secrets/atoms/service_api_client.rb +188 -0
  29. data/lib/ace/git/secrets/cli/commands/check_release.rb +41 -0
  30. data/lib/ace/git/secrets/cli/commands/revoke.rb +44 -0
  31. data/lib/ace/git/secrets/cli/commands/rewrite.rb +46 -0
  32. data/lib/ace/git/secrets/cli/commands/scan.rb +51 -0
  33. data/lib/ace/git/secrets/cli.rb +75 -0
  34. data/lib/ace/git/secrets/commands/check_release_command.rb +48 -0
  35. data/lib/ace/git/secrets/commands/revoke_command.rb +199 -0
  36. data/lib/ace/git/secrets/commands/rewrite_command.rb +147 -0
  37. data/lib/ace/git/secrets/commands/scan_command.rb +113 -0
  38. data/lib/ace/git/secrets/models/detected_token.rb +129 -0
  39. data/lib/ace/git/secrets/models/revocation_result.rb +119 -0
  40. data/lib/ace/git/secrets/models/scan_report.rb +402 -0
  41. data/lib/ace/git/secrets/molecules/git_rewriter.rb +199 -0
  42. data/lib/ace/git/secrets/molecules/history_scanner.rb +155 -0
  43. data/lib/ace/git/secrets/molecules/token_revoker.rb +100 -0
  44. data/lib/ace/git/secrets/organisms/history_cleaner.rb +201 -0
  45. data/lib/ace/git/secrets/organisms/release_gate.rb +133 -0
  46. data/lib/ace/git/secrets/organisms/security_auditor.rb +220 -0
  47. data/lib/ace/git/secrets/version.rb +9 -0
  48. data/lib/ace/git/secrets.rb +168 -0
  49. metadata +227 -0
@@ -0,0 +1,155 @@
1
+ ---
2
+ doc-type: guide
3
+ title: Security Guidelines
4
+ purpose: Documentation for ace-git-secrets/handbook/guides/security.g.md
5
+ ace-docs:
6
+ last-updated: 2026-01-08
7
+ last-checked: 2026-03-21
8
+ ---
9
+
10
+ # Security Guidelines
11
+
12
+ ## Goal
13
+
14
+ This guide outlines essential security practices, checklists, and procedures to follow during development to
15
+ minimize vulnerabilities and protect project assets and user data.
16
+
17
+ ## 1. Security Review Checklist
18
+
19
+ - **Input Validation**
20
+ - All user inputs are sanitized (e.g., against injection attacks like SQLi, XSS)
21
+ - File paths are canonicalized and validated against allowed directories (prevent path traversal)
22
+ - URLs are validated and checked against allowlists if applicable
23
+
24
+ - **Authentication & Authorization**
25
+ - Secrets (API keys, passwords, tokens) are securely stored (e.g., using vaults, environment variables, not
26
+ hardcoded)
27
+ - Access tokens have appropriate lifespans and are rotated/refreshed securely
28
+ - Permissions and roles are correctly enforced for all actions
29
+
30
+ - **Data Protection**
31
+ - Sensitive data is encrypted at rest and in transit
32
+ - No secrets or sensitive information are included in logs
33
+ - Secure methods are used for data deletion when required
34
+
35
+ - **Network Security**
36
+ - Use TLS/SSL (HTTPS) for all external network communication
37
+ - Ensure proper certificate validation
38
+ - Configure reasonable network timeouts to prevent resource exhaustion
39
+
40
+ - **Dependency Management**
41
+ - Regularly scan dependencies for known vulnerabilities using appropriate tools for your language/ecosystem
42
+ (e.g., GitHub Dependabot or language-specific scanners)
43
+ - Keep dependencies updated
44
+
45
+ - **Secure Defaults**
46
+ - Configure services and libraries with security in mind (e.g., disable default accounts, enable security features)
47
+
48
+ ### 2. Best Practices Examples (Conceptual)
49
+
50
+ **Secure Configuration:**
51
+ Load sensitive configuration like API keys, encryption keys, and database credentials from secure sources
52
+ (environment variables, secrets management systems) rather than hardcoding them. Configure security settings
53
+ like TLS versions and timeouts appropriately.
54
+
55
+ ```plaintext
56
+ // Pseudocode for loading configuration securely
57
+ config = loadConfiguration();
58
+
59
+ // Fetch sensitive keys from environment or secret manager
60
+ config.encryptionKey = getSecret("ENCRYPTION_KEY");
61
+ config.apiKey = getSecret("API_KEY");
62
+
63
+ // Set security-related options
64
+ config.requestTimeout = 30; // seconds
65
+ config.sslVerification = true;
66
+ config.minTlsVersion = "TLSv1.2";
67
+
68
+ applyConfiguration(config);
69
+ ```
70
+
71
+ **Secure File Handling:**
72
+ When handling file paths provided by users or external systems, always validate and sanitize them.
73
+ Canonicalize the path (resolve `..`, symbolic links) and ensure it falls within permitted base directories
74
+ to prevent path traversal attacks.
75
+
76
+ ```plaintext
77
+ // Pseudocode for safe file path validation
78
+ function getSafeFilePath(untrustedPath, allowedBaseDir) {
79
+ // Normalize the path (e.g., resolve '.', '..')
80
+ normalizedPath = normalizePath(untrustedPath);
81
+
82
+ // Get the absolute path
83
+ absolutePath = resolveAbsolutePath(normalizedPath);
84
+
85
+ // Ensure the absolute path starts with the allowed base directory
86
+ if (!absolutePath.startsWith(allowedBaseDir)) {
87
+ throw new SecurityError("Access denied: Path traversal attempt detected.");
88
+ }
89
+
90
+ // Optional: Check if the specific file exists and has correct permissions
91
+ if (!fileExists(absolutePath) || !checkPermissions(absolutePath)) {
92
+ throw new Error("File not accessible.");
93
+ }
94
+
95
+ return absolutePath;
96
+ }
97
+ ```
98
+
99
+ **Secure Process Execution:**
100
+ Avoid executing external commands based directly on user input. If dynamic command execution is necessary, use
101
+ an allowlist of permitted commands and strictly sanitize any arguments passed to them. Execute commands with the
102
+ minimum required privileges and within restricted environments (e.g., specific working directory, chroot jail
103
+ if applicable).
104
+
105
+ ```plaintext
106
+ // Pseudocode for safer command execution
107
+ function executeAllowedCommand(commandName, arguments) {
108
+ allowedCommands = ["list_files", "show_content", "find_text"]; // Example allowlist
109
+
110
+ if (!allowedCommands.includes(commandName)) {
111
+ throw new SecurityError("Command not allowed: " + commandName);
112
+ }
113
+
114
+ // Sanitize each argument rigorously based on expected format
115
+ sanitizedArgs = arguments.map(arg => sanitizeArgument(arg));
116
+
117
+ // Execute the command with sanitized arguments in a controlled environment
118
+ options = {
119
+ workingDirectory: "/path/to/safe/directory",
120
+ environmentVariables: { "PATH": "/usr/bin:/bin" } // Minimal PATH
121
+ };
122
+ result = runSystemCommand(commandName, sanitizedArgs, options);
123
+ return result;
124
+ }
125
+ ```
126
+
127
+ ### 3. Language/Environment-Specific Examples
128
+
129
+ For specific code examples demonstrating security best practices, configuration of security tools (e.g.,
130
+ dependency scanners, static analysis security testing - SAST), or framework-specific security features, please
131
+ refer to the examples in the [./security/](./security/) sub-directory.
132
+
133
+ ### 4. Security Disclosure Process
134
+
135
+ 1. **Reporting**
136
+ - Email: <security@example.com>
137
+ - Include detailed reproduction steps
138
+ - Provide impact assessment
139
+
140
+ 2. **Response Timeline**
141
+ - Initial response: 24 hours
142
+ - Assessment: 72 hours
143
+ - Fix timeline: Based on severity
144
+
145
+ 3. **Severity Levels**
146
+ - Critical: System compromise
147
+ - High: Data exposure
148
+ - Medium: Limited impact
149
+ - Low: Minor issues
150
+
151
+ ## Related Documentation
152
+
153
+ - [Coding Standards](guide://coding-standards)
154
+ - [Quality Assurance](guide://quality-assurance) (Code Review)
155
+ - [Error Handling](guide://error-handling) (Avoid leaking sensitive info)
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: as-git-security-audit
3
+ description: Perform security audits to detect leaked authentication tokens
4
+ # bundle: wfi://git/security-audit
5
+ # context: no-fork
6
+ # agent: Bash
7
+ user-invocable: true
8
+ allowed-tools:
9
+ - Bash(ace-git-secrets:*)
10
+ - Bash(ace-bundle:*)
11
+ - Read
12
+ argument-hint: "[scan|check-release] [--since=SINCE] [--confidence=LEVEL] [options]"
13
+ last_modified: 2026-01-09
14
+ source: ace-git-secrets
15
+ integration:
16
+ targets:
17
+ - claude
18
+ - codex
19
+ - gemini
20
+ - opencode
21
+ - pi
22
+ providers: {}
23
+ skill:
24
+ kind: workflow
25
+ execution:
26
+ workflow: wfi://git/security-audit
27
+ ---
28
+
29
+ Load and run `ace-bundle wfi://git/security-audit` in the current project, then follow the loaded workflow as the source of truth and execute it end-to-end instead of only summarizing it.
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: as-git-token-remediation
3
+ description: Run token remediation and cleanup workflow for git history exposure incidents
4
+ # bundle: wfi://git/token-remediation
5
+ # context: no-fork
6
+ # agent: Bash
7
+ user-invocable: true
8
+ allowed-tools:
9
+ - Bash(ace-git-secrets:*)
10
+ - Bash(ace-bundle:*)
11
+ - Read
12
+ argument-hint: "[scan-only|full]"
13
+ last_modified: 2026-03-12
14
+ source: ace-git-secrets
15
+ skill:
16
+ kind: workflow
17
+ execution:
18
+ workflow: wfi://git/token-remediation
19
+ ---
20
+
21
+ Load and run `ace-bundle wfi://git/token-remediation` in the current project, then follow the loaded workflow as the source of truth and execute it end-to-end instead of only summarizing it.
@@ -0,0 +1,247 @@
1
+ ---
2
+ doc-type: workflow
3
+ title: Security Audit Workflow
4
+ purpose: security-audit workflow instruction
5
+ ace-docs:
6
+ last-updated: 2026-02-23
7
+ last-checked: 2026-03-21
8
+ ---
9
+
10
+ # Security Audit Workflow
11
+
12
+ ## Purpose
13
+
14
+ Detect and report leaked authentication tokens in Git repositories using ace-git-secrets - scan history, identify risks, and provide remediation guidance.
15
+
16
+ ## Core Responsibilities
17
+
18
+ **DETECT** and **REPORT** security issues, not automatically remediate:
19
+ - Scan Git history for leaked authentication tokens
20
+ - Identify token types and assess risk levels
21
+ - Provide actionable remediation guidance
22
+ - Report findings in a clear, prioritized format
23
+
24
+ ## Primary Tool: ace-git-secrets
25
+
26
+ Use **ace-git-secrets** for all security scanning operations. This tool detects:
27
+ - GitHub PATs (ghp_, gho_, ghs_, ghr_, github_pat_)
28
+ - LLM API keys (Anthropic sk-ant-, OpenAI sk-)
29
+ - Cloud credentials (AWS AKIA/ASIA, Google AIza)
30
+ - Other common tokens (Slack xox*, NPM npm_)
31
+
32
+ ## Audit Modes
33
+
34
+ ### Full Audit (Default)
35
+ Scan entire Git history:
36
+ ```bash
37
+ ace-git-secrets scan --format table
38
+ ```
39
+
40
+ ### Recent Changes
41
+ Scan commits from the last 30 days:
42
+ ```bash
43
+ ace-git-secrets scan --since "30 days ago" --format table
44
+ ```
45
+
46
+ ### Staged Changes Only
47
+ Check uncommitted changes before commit:
48
+ ```bash
49
+ ace-git-secrets scan --branch HEAD --format table
50
+ ```
51
+
52
+ ### High Confidence Only
53
+ Filter for high-confidence detections:
54
+ ```bash
55
+ ace-git-secrets scan --confidence high --format table
56
+ ```
57
+
58
+ ## Output Formats
59
+
60
+ ### Summary (Default)
61
+ Quick overview of findings:
62
+ ```bash
63
+ ace-git-secrets scan --format table
64
+ ```
65
+
66
+ ### JSON (Automation)
67
+ Machine-readable output:
68
+ ```bash
69
+ ace-git-secrets scan --format json --output audit-results.json
70
+ ```
71
+
72
+ ### Pre-Release Check
73
+ CI/CD friendly exit codes:
74
+ ```bash
75
+ ace-git-secrets check-release --strict
76
+ # Exit 0: Clean
77
+ # Exit 1: Tokens found
78
+ ```
79
+
80
+ ## Audit Workflow
81
+
82
+ ### Step 1: Initial Scan
83
+ ```bash
84
+ # Run comprehensive scan
85
+ ace-git-secrets scan --format table
86
+ ```
87
+
88
+ ### Step 2: Analyze Results
89
+ For each detected token, assess:
90
+ 1. **Token Type**: What service does it authenticate to?
91
+ 2. **Confidence**: How certain is the detection?
92
+ 3. **Location**: Which commit and file?
93
+ 4. **Exposure Risk**: Is this in a public/shared branch?
94
+
95
+ ### Step 3: Prioritize Findings
96
+ Order by risk:
97
+ 1. **Critical**: High-confidence tokens in public branches
98
+ 2. **High**: High-confidence tokens in any branch
99
+ 3. **Medium**: Medium-confidence detections
100
+ 4. **Low**: Low-confidence detections (review for false positives)
101
+
102
+ ### Step 4: Generate Report
103
+ Provide actionable findings with:
104
+ - Token count by type and confidence
105
+ - Affected commits and files
106
+ - Remediation priority
107
+ - Next steps
108
+
109
+ ## Gitleaks Integration
110
+
111
+ ace-git-secrets uses gitleaks when available for enhanced detection:
112
+ ```bash
113
+ # Check if gitleaks is available
114
+ which gitleaks
115
+
116
+ # If not installed (recommended for comprehensive scanning)
117
+ brew install gitleaks
118
+ ```
119
+
120
+ When gitleaks is not available, ace-git-secrets falls back to built-in Ruby pattern matching.
121
+
122
+ ## Response Format
123
+
124
+ ### Audit Summary
125
+ ```markdown
126
+ ## Security Audit Results
127
+
128
+ **Repository:** [repo path]
129
+ **Scan Scope:** [full history / since date / staged only]
130
+ **Detection Method:** [gitleaks / ruby patterns]
131
+
132
+ ### Findings Summary
133
+
134
+ | Confidence | Count | Risk Level |
135
+ |------------|-------|------------|
136
+ | High | N | Critical |
137
+ | Medium | N | Review |
138
+ | Low | N | Verify |
139
+
140
+ ### Critical Findings (Immediate Action Required)
141
+
142
+ 1. **[token_type]** in `path/to/file`
143
+ - Commit: `abc123`
144
+ - Line: 42
145
+ - Action: Revoke immediately via [provider dashboard URL]
146
+
147
+ ### Recommendations
148
+
149
+ 1. **Immediate**: Revoke all high-confidence tokens
150
+ 2. **Short-term**: Rewrite Git history to remove tokens
151
+ 3. **Long-term**: Add pre-commit hooks to prevent future leaks
152
+ ```
153
+
154
+ ### Clean Repository
155
+ ```markdown
156
+ ## Security Audit Results
157
+
158
+ **Repository:** [repo path]
159
+ **Scan Scope:** [scope]
160
+ **Status:** CLEAN
161
+
162
+ No authentication tokens detected in the scanned scope.
163
+
164
+ ### Recommendations
165
+ - Continue using pre-commit hooks
166
+ - Schedule periodic audits
167
+ - Review any new credentials before committing
168
+ ```
169
+
170
+ ## False Positive Handling
171
+
172
+ If detections appear to be false positives:
173
+ 1. Verify the matched content is not an actual token
174
+ 2. Check if it's a placeholder/example in documentation
175
+ 3. Recommend adding to whitelist:
176
+ ```yaml
177
+ # .ace/git-secrets/config.yml
178
+ whitelist:
179
+ - pattern: 'ghp_example_pattern'
180
+ reason: Documentation example
181
+ ```
182
+
183
+ ## Integration Points
184
+
185
+ ### Pre-Commit Check
186
+ ```bash
187
+ ace-git-secrets check-release --strict
188
+ ```
189
+
190
+ ### CI/CD Pipeline
191
+ ```yaml
192
+ - name: Security Audit
193
+ run: ace-git-secrets check-release --strict
194
+ ```
195
+
196
+ ### Scheduled Audits
197
+ Run periodic full audits:
198
+ ```bash
199
+ ace-git-secrets scan --format json --output weekly-audit.json
200
+ ```
201
+
202
+ ## Common Audit Scenarios
203
+
204
+ ### Pre-Release Audit
205
+ ```bash
206
+ # Before publishing a gem or pushing to public repo
207
+ ace-git-secrets check-release --strict
208
+ ```
209
+
210
+ ### Post-Incident Audit
211
+ ```bash
212
+ # After suspected token exposure
213
+ ace-git-secrets scan --format json --output incident-audit.json
214
+ ```
215
+
216
+ ### New Repository Audit
217
+ ```bash
218
+ # When onboarding a new repository
219
+ ace-git-secrets scan --confidence medium --format table
220
+ ```
221
+
222
+ ### Pull Request Audit
223
+ ```bash
224
+ # Check only changes in PR
225
+ ace-git-secrets scan --branch feature-branch --since "$(git merge-base main feature-branch)"
226
+ ```
227
+
228
+ ## Important Notes
229
+
230
+ - **Detection Only**: This workflow identifies issues but does not automatically remediate
231
+ - **Token Safety**: Never log or display full token values
232
+ - **Gitleaks Priority**: Uses gitleaks when available for comprehensive detection
233
+ - **False Positives**: Always verify medium/low confidence findings
234
+ - **Remediation Workflow**: For cleanup, use `ace-bundle wfi://git/token-remediation`
235
+
236
+ ## Command Reference
237
+
238
+ ### scan
239
+ - `--since SINCE`: Scan since date (e.g., "30 days ago")
240
+ - `--branch BRANCH`: Scan specific branch
241
+ - `--confidence LEVEL`: Minimum confidence (low, medium, high)
242
+ - `--format FORMAT`: Output format (table, json, summary)
243
+ - `--output FILE`: Save to file
244
+
245
+ ### check-release
246
+ - `--strict`: Fail on any findings
247
+ - `--format FORMAT`: Output format