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
data/docs/handbook.md ADDED
@@ -0,0 +1,43 @@
1
+ ---
2
+ doc-type: user
3
+ title: ace-git-secrets Handbook Catalog
4
+ purpose: Catalog of ace-git-secrets workflows, skills, guides, and agents
5
+ ace-docs:
6
+ last-updated: 2026-03-22
7
+ last-checked: 2026-03-22
8
+ ---
9
+
10
+ # ace-git-secrets Handbook Catalog
11
+
12
+ Reference for package-owned handbook resources in `ace-git-secrets/handbook/`.
13
+
14
+ ## Skills
15
+
16
+ | Skill | What it does |
17
+ |-------|--------------|
18
+ | `as-git-security-audit` | Run the package security-audit workflow to detect leaked tokens and report remediation guidance |
19
+ | `as-git-token-remediation` | Run the package remediation workflow to scan, revoke, and clean leaked credentials |
20
+
21
+ ## Workflow Instructions
22
+
23
+ | Protocol Path | Purpose | Invoked by |
24
+ |---------------|---------|------------|
25
+ | `wfi://git/security-audit` | Guided detection and reporting workflow for leaked credentials | `as-git-security-audit` |
26
+ | `wfi://git/token-remediation` | Guided remediation workflow covering scan, revoke, rewrite, and follow-up actions | `as-git-token-remediation` |
27
+
28
+ ## Agents
29
+
30
+ - `handbook/agents/security-audit.ag.md` for focused security-audit execution
31
+
32
+ ## Guides
33
+
34
+ - `handbook/guides/security.g.md` for package-level security guidance
35
+ - `handbook/guides/security/ruby.md` for Ruby-specific security notes
36
+ - `handbook/guides/security/typescript.md` for TypeScript-specific security notes
37
+ - `handbook/guides/security/rust.md` for Rust-specific security notes
38
+
39
+ ## Related Docs
40
+
41
+ - [Getting Started](getting-started.md)
42
+ - [CLI Usage Reference](usage.md)
43
+ - Load workflows directly with `ace-bundle`, for example `ace-bundle wfi://git/token-remediation`
data/docs/usage.md ADDED
@@ -0,0 +1,301 @@
1
+ ---
2
+ doc-type: user
3
+ title: ace-git-secrets Usage Guide
4
+ purpose: CLI reference for ace-git-secrets
5
+ ace-docs:
6
+ last-updated: 2026-03-22
7
+ last-checked: 2026-03-22
8
+ ---
9
+
10
+ # ace-git-secrets Usage Guide
11
+
12
+ Reference for scanning, revoking, and removing leaked credentials from Git history.
13
+
14
+ ## Quick Start
15
+
16
+ Run a scan first and keep the saved JSON report path:
17
+
18
+ ```bash
19
+ ace-git-secrets scan
20
+ ```
21
+
22
+ Then use that saved report for the rest of the remediation flow:
23
+
24
+ ```bash
25
+ ace-git-secrets revoke --scan-file .ace-local/git-secrets/sessions/<id>-report.json
26
+ ace-git-secrets rewrite-history --dry-run --scan-file .ace-local/git-secrets/sessions/<id>-report.json
27
+ ace-git-secrets rewrite-history --scan-file .ace-local/git-secrets/sessions/<id>-report.json
28
+ ```
29
+
30
+ ## Commands
31
+
32
+ ### scan
33
+
34
+ Scan Git history for authentication tokens.
35
+
36
+ ```bash
37
+ ace-git-secrets scan [OPTIONS]
38
+ ```
39
+
40
+ Behavior:
41
+
42
+ - Summary output goes to stdout by default
43
+ - A full report is always saved to `.ace-local/git-secrets/sessions/`
44
+ - The saved JSON report includes raw token values needed by `revoke` and `rewrite-history`
45
+
46
+ Options:
47
+
48
+ - `--since=VALUE` - Start scanning from a commit or date
49
+ - `--format=VALUE, -f` - Stdout format when `--verbose` is enabled: `table`, `json`, `yaml`
50
+ - `--report-format=VALUE, -r` - Saved report format: `json`, `markdown`
51
+ - `--confidence=VALUE, -c` - Minimum confidence: `high`, `medium`, `low`
52
+ - `--[no-]verbose` - Print the full report to stdout in addition to saving it
53
+ - `--[no-]quiet, -q` - Suppress non-essential output for CI-style usage
54
+ - `--[no-]debug` - Show debug output
55
+
56
+ Examples:
57
+
58
+ ```bash
59
+ # Scan full history
60
+ ace-git-secrets scan
61
+
62
+ # Scan recent history only
63
+ ace-git-secrets scan --since "30 days ago"
64
+
65
+ # Review only high-confidence findings in verbose JSON
66
+ ace-git-secrets scan --confidence high --verbose --format json
67
+
68
+ # Save a human-readable report as Markdown instead of JSON
69
+ ace-git-secrets scan --report-format markdown
70
+
71
+ # Minimal output for automation
72
+ ace-git-secrets scan --quiet
73
+ ```
74
+
75
+ ### revoke
76
+
77
+ Revoke detected tokens via provider APIs.
78
+
79
+ ```bash
80
+ ace-git-secrets revoke [OPTIONS]
81
+ ```
82
+
83
+ Options:
84
+
85
+ - `--service=VALUE, -s` - Revoke for one provider only
86
+ - `--token=VALUE, -t` - Revoke one explicit token value
87
+ - `--scan-file=VALUE` - Load tokens from a saved scan report
88
+ - `--[no-]debug` - Show debug output
89
+
90
+ Examples:
91
+
92
+ ```bash
93
+ # Revoke all high-confidence tokens from a fresh scan
94
+ ace-git-secrets revoke
95
+
96
+ # Revoke only GitHub tokens from a saved scan report
97
+ ace-git-secrets revoke --service github --scan-file .ace-local/git-secrets/sessions/<id>-report.json
98
+
99
+ # Revoke one token directly
100
+ ace-git-secrets revoke --token "ghp_example_token"
101
+ ```
102
+
103
+ Notes:
104
+
105
+ - `--scan-file` expects the saved JSON report produced by `scan`
106
+ - Redirecting verbose stdout to a file is not a supported substitute, because `revoke` requires `raw_value` fields
107
+ - If the scan file is missing `raw_value`, re-run `ace-git-secrets scan` and use the saved report path it prints
108
+
109
+ ### rewrite-history
110
+
111
+ Remove detected tokens from Git history.
112
+
113
+ ```bash
114
+ ace-git-secrets rewrite-history [OPTIONS]
115
+ ```
116
+
117
+ `rewrite-history` is destructive. Run it only after revoking the exposed credentials and after previewing the result with
118
+ `--dry-run`.
119
+
120
+ Options:
121
+
122
+ - `--[no-]dry-run, -n` - Show what would be rewritten without modifying history
123
+ - `--[no-]backup` - Create a backup before rewriting (enabled by default)
124
+ - `--[no-]force` - Skip the confirmation prompt
125
+ - `--scan-file=VALUE` - Load tokens from a saved scan report
126
+ - `--[no-]debug` - Show debug output
127
+
128
+ Examples:
129
+
130
+ ```bash
131
+ # Preview cleanup first
132
+ ace-git-secrets rewrite-history --dry-run --scan-file .ace-local/git-secrets/sessions/<id>-report.json
133
+
134
+ # Rewrite history using the same saved report used for revocation
135
+ ace-git-secrets rewrite-history --scan-file .ace-local/git-secrets/sessions/<id>-report.json
136
+
137
+ # Rewrite without a prompt
138
+ ace-git-secrets rewrite-history --force --scan-file .ace-local/git-secrets/sessions/<id>-report.json
139
+ ```
140
+
141
+ Before running the real rewrite:
142
+
143
+ - install `git-filter-repo`
144
+ - start from a clean working tree
145
+ - keep a mirror or clone backup for recovery
146
+
147
+ ### check-release
148
+
149
+ Run the pre-release security gate.
150
+
151
+ ```bash
152
+ ace-git-secrets check-release [OPTIONS]
153
+ ```
154
+
155
+ Options:
156
+
157
+ - `--[no-]strict` - Fail on medium-confidence matches in addition to high-confidence matches
158
+ - `--format=VALUE, -f` - Output format: `table`, `json`
159
+ - `--[no-]debug` - Show debug output
160
+
161
+ Examples:
162
+
163
+ ```bash
164
+ # Standard release gate
165
+ ace-git-secrets check-release
166
+
167
+ # Stricter release gate for CI
168
+ ace-git-secrets check-release --strict
169
+
170
+ # Structured review output
171
+ ace-git-secrets check-release --format json
172
+ ```
173
+
174
+ Prefer exit codes for automation. `check-release --format json` currently includes banner text, so it is better suited to
175
+ inspection than strict machine parsing.
176
+
177
+ ## Configuration
178
+
179
+ Configuration follows the ACE cascade. Project overrides live in `.ace/git-secrets/config.yml`.
180
+
181
+ ```yaml
182
+ exclusions:
183
+ - "**/node_modules/**"
184
+ - "**/vendor/**"
185
+
186
+ whitelist:
187
+ - pattern: "ghp_example_for_docs"
188
+ reason: "Documentation example"
189
+ - file: "test/fixtures/*.json"
190
+ reason: "Test fixtures"
191
+
192
+ output:
193
+ format: table
194
+ mask_tokens: true
195
+ directory: .ace-local/git-secrets
196
+
197
+ github:
198
+ api_url: https://github.mycompany.com/api/v3
199
+ ```
200
+
201
+ Use whitelist rules for known safe examples or fixtures. Keep real credentials out of the whitelist and revoke them
202
+ instead.
203
+
204
+ ## Common Workflows
205
+
206
+ ### Full remediation loop
207
+
208
+ 1. Scan and note the saved report path:
209
+
210
+ ```bash
211
+ ace-git-secrets scan
212
+ ```
213
+
214
+ 2. Revoke from the saved JSON report:
215
+
216
+ ```bash
217
+ ace-git-secrets revoke --scan-file .ace-local/git-secrets/sessions/<id>-report.json
218
+ ```
219
+
220
+ 3. Preview history rewriting:
221
+
222
+ ```bash
223
+ ace-git-secrets rewrite-history --dry-run --scan-file .ace-local/git-secrets/sessions/<id>-report.json
224
+ ```
225
+
226
+ 4. Rewrite history for real:
227
+
228
+ ```bash
229
+ ace-git-secrets rewrite-history --scan-file .ace-local/git-secrets/sessions/<id>-report.json
230
+ ```
231
+
232
+ 5. Re-scan or run the release gate:
233
+
234
+ ```bash
235
+ ace-git-secrets check-release --strict
236
+ ```
237
+
238
+ ### Human-readable reporting
239
+
240
+ Generate a Markdown report when you need to share findings with reviewers:
241
+
242
+ ```bash
243
+ ace-git-secrets scan --report-format markdown
244
+ ```
245
+
246
+ ### Faster large-repository scans
247
+
248
+ Limit the scan scope for triage work:
249
+
250
+ ```bash
251
+ ace-git-secrets scan --since "6 months ago"
252
+ ```
253
+
254
+ ## Exit Codes
255
+
256
+ | Code | Meaning |
257
+ |------|---------|
258
+ | `0` | Success, or no tokens found for scan/check workflows |
259
+ | `1` | Tokens found, or partial revocation success/failure |
260
+ | `2` | Command error such as missing dependencies, invalid input, or I/O failure |
261
+
262
+ ## Troubleshooting
263
+
264
+ ### "gitleaks is required"
265
+
266
+ Install the scanner and re-run:
267
+
268
+ ```bash
269
+ brew install gitleaks
270
+ ```
271
+
272
+ ### "git-filter-repo is required"
273
+
274
+ Install the rewrite tool before using `rewrite-history`:
275
+
276
+ ```bash
277
+ brew install git-filter-repo
278
+ ```
279
+
280
+ ### Scan file missing `raw_value`
281
+
282
+ Re-run `scan` and use the saved JSON report path that the command prints. Do not build the `--scan-file` input by
283
+ redirecting verbose stdout.
284
+
285
+ ### Scan is slow on a large repository
286
+
287
+ Limit the scan window:
288
+
289
+ ```bash
290
+ ace-git-secrets scan --since "30 days ago"
291
+ ```
292
+
293
+ ### False positives
294
+
295
+ Add a whitelist entry for known safe examples or fixtures in `.ace/git-secrets/config.yml`.
296
+
297
+ ## Related Docs
298
+
299
+ - [Getting Started](getting-started.md)
300
+ - [Handbook Catalog](handbook.md)
301
+ - Runtime help: `ace-git-secrets --help`
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/ace/git/secrets"
5
+ require "ace/support/cli"
6
+
7
+ args = ARGV.empty? ? ["--help"] : ARGV
8
+
9
+ # Start ace-support-cli with exception-based exit code handling (per ADR-023)
10
+ begin
11
+ # Preload config before dispatch to avoid first-access races in parallel contexts.
12
+ Ace::Git::Secrets.config
13
+ Ace::Support::Cli::Runner.new(Ace::Git::Secrets::CLI).call(args: args)
14
+ rescue SystemExit => e
15
+ exit(e.status)
16
+ rescue Ace::Support::Cli::Error => e
17
+ warn e.message
18
+ exit(e.exit_code)
19
+ end
@@ -0,0 +1,237 @@
1
+ ---
2
+ name: security-audit
3
+ description: Perform security audits to detect leaked authentication tokens in Git repositories
4
+ expected_params:
5
+ required: []
6
+ optional:
7
+ - scope: 'Audit scope: full (all history), recent (last 30 days), staged (uncommitted)'
8
+ - confidence: 'Minimum confidence level: low, medium, high (default: medium)'
9
+ - format: 'Output format: table, json, summary (default: summary)'
10
+ last_modified: '2025-12-20'
11
+ type: agent
12
+ source: ace-git-secrets
13
+ ---
14
+
15
+ You are a security audit specialist focused on detecting leaked authentication tokens in Git repositories using the **ace-git-secrets** gem.
16
+
17
+ ## Core Responsibilities
18
+
19
+ Your primary role is to **DETECT** and **REPORT** security issues, not to automatically remediate them:
20
+ - Scan Git history for leaked authentication tokens
21
+ - Identify token types and assess risk levels
22
+ - Provide actionable remediation guidance
23
+ - Report findings in a clear, prioritized format
24
+
25
+ ## Primary Tool: ace-git-secrets
26
+
27
+ You use **ace-git-secrets** for all security scanning operations. This tool detects:
28
+ - GitHub PATs (ghp_, gho_, ghs_, ghr_, github_pat_)
29
+ - LLM API keys (Anthropic sk-ant-, OpenAI sk-)
30
+ - Cloud credentials (AWS AKIA/ASIA, Google AIza)
31
+ - Other common tokens (Slack xox*, NPM npm_)
32
+
33
+ ## Audit Modes
34
+
35
+ ### Full Audit (Default)
36
+ Scan entire Git history:
37
+ ```bash
38
+ ace-git-secrets scan --format table
39
+ ```
40
+
41
+ ### Recent Changes
42
+ Scan commits from the last 30 days:
43
+ ```bash
44
+ ace-git-secrets scan --since "30 days ago" --format table
45
+ ```
46
+
47
+ ### Staged Changes Only
48
+ Check uncommitted changes before commit:
49
+ ```bash
50
+ ace-git-secrets scan --branch HEAD --format table
51
+ ```
52
+
53
+ ### High Confidence Only
54
+ Filter for high-confidence detections:
55
+ ```bash
56
+ ace-git-secrets scan --confidence high --format table
57
+ ```
58
+
59
+ ## Output Formats
60
+
61
+ ### Summary (Default)
62
+ Quick overview of findings:
63
+ ```bash
64
+ ace-git-secrets scan --format table
65
+ ```
66
+
67
+ ### JSON (Automation)
68
+ Machine-readable output:
69
+ ```bash
70
+ ace-git-secrets scan --format json --output audit-results.json
71
+ ```
72
+
73
+ ### Pre-Release Check
74
+ CI/CD friendly exit codes:
75
+ ```bash
76
+ ace-git-secrets check-release --strict
77
+ # Exit 0: Clean
78
+ # Exit 1: Tokens found
79
+ ```
80
+
81
+ ## Audit Workflow
82
+
83
+ ### Step 1: Initial Scan
84
+ ```bash
85
+ # Run comprehensive scan
86
+ ace-git-secrets scan --format table
87
+ ```
88
+
89
+ ### Step 2: Analyze Results
90
+ For each detected token, assess:
91
+ 1. **Token Type**: What service does it authenticate to?
92
+ 2. **Confidence**: How certain is the detection?
93
+ 3. **Location**: Which commit and file?
94
+ 4. **Exposure Risk**: Is this in a public/shared branch?
95
+
96
+ ### Step 3: Prioritize Findings
97
+ Order by risk:
98
+ 1. **Critical**: High-confidence tokens in public branches
99
+ 2. **High**: High-confidence tokens in any branch
100
+ 3. **Medium**: Medium-confidence detections
101
+ 4. **Low**: Low-confidence detections (review for false positives)
102
+
103
+ ### Step 4: Generate Report
104
+ Provide actionable findings with:
105
+ - Token count by type and confidence
106
+ - Affected commits and files
107
+ - Remediation priority
108
+ - Next steps
109
+
110
+ ## Gitleaks Integration
111
+
112
+ ace-git-secrets uses gitleaks when available for enhanced detection:
113
+ ```bash
114
+ # Check if gitleaks is available
115
+ which gitleaks
116
+
117
+ # If not installed (recommended for comprehensive scanning)
118
+ brew install gitleaks
119
+ ```
120
+
121
+ When gitleaks is not available, ace-git-secrets falls back to built-in Ruby pattern matching.
122
+
123
+ ## Response Format
124
+
125
+ ### Audit Summary
126
+ ```markdown
127
+ ## Security Audit Results
128
+
129
+ **Repository:** [repo path]
130
+ **Scan Scope:** [full history / since date / staged only]
131
+ **Detection Method:** [gitleaks / ruby patterns]
132
+
133
+ ### Findings Summary
134
+
135
+ | Confidence | Count | Risk Level |
136
+ |------------|-------|------------|
137
+ | High | N | Critical |
138
+ | Medium | N | Review |
139
+ | Low | N | Verify |
140
+
141
+ ### Critical Findings (Immediate Action Required)
142
+
143
+ 1. **[token_type]** in `path/to/file`
144
+ - Commit: `abc123`
145
+ - Line: 42
146
+ - Action: Revoke immediately via [provider dashboard URL]
147
+
148
+ ### Recommendations
149
+
150
+ 1. **Immediate**: Revoke all high-confidence tokens
151
+ 2. **Short-term**: Rewrite Git history to remove tokens
152
+ 3. **Long-term**: Add pre-commit hooks to prevent future leaks
153
+ ```
154
+
155
+ ### Clean Repository
156
+ ```markdown
157
+ ## Security Audit Results
158
+
159
+ **Repository:** [repo path]
160
+ **Scan Scope:** [scope]
161
+ **Status:** CLEAN
162
+
163
+ No authentication tokens detected in the scanned scope.
164
+
165
+ ### Recommendations
166
+ - Continue using pre-commit hooks
167
+ - Schedule periodic audits
168
+ - Review any new credentials before committing
169
+ ```
170
+
171
+ ## False Positive Handling
172
+
173
+ If detections appear to be false positives:
174
+ 1. Verify the matched content is not an actual token
175
+ 2. Check if it's a placeholder/example in documentation
176
+ 3. Recommend adding to whitelist:
177
+ ```yaml
178
+ # .ace/git-secrets/config.yml
179
+ whitelist:
180
+ - pattern: 'ghp_example_pattern'
181
+ reason: Documentation example
182
+ ```
183
+
184
+ ## Integration Points
185
+
186
+ ### Pre-Commit Check
187
+ ```bash
188
+ ace-git-secrets check-release --strict
189
+ ```
190
+
191
+ ### CI/CD Pipeline
192
+ ```yaml
193
+ - name: Security Audit
194
+ run: ace-git-secrets check-release --strict
195
+ ```
196
+
197
+ ### Scheduled Audits
198
+ Run periodic full audits:
199
+ ```bash
200
+ ace-git-secrets scan --format json --output weekly-audit.json
201
+ ```
202
+
203
+ ## Important Notes
204
+
205
+ - **Detection Only**: This agent identifies issues but does not automatically remediate
206
+ - **Token Safety**: Never log or display full token values
207
+ - **Gitleaks Priority**: Uses gitleaks when available for comprehensive detection
208
+ - **False Positives**: Always verify medium/low confidence findings
209
+ - **Remediation Workflow**: Direct users to `token-remediation.wf.md` for cleanup
210
+
211
+ ## Common Audit Scenarios
212
+
213
+ ### Pre-Release Audit
214
+ ```bash
215
+ # Before publishing a gem or pushing to public repo
216
+ ace-git-secrets check-release --strict
217
+ ```
218
+
219
+ ### Post-Incident Audit
220
+ ```bash
221
+ # After suspected token exposure
222
+ ace-git-secrets scan --format json --output incident-audit.json
223
+ ```
224
+
225
+ ### New Repository Audit
226
+ ```bash
227
+ # When onboarding a new repository
228
+ ace-git-secrets scan --confidence medium --format table
229
+ ```
230
+
231
+ ### Pull Request Audit
232
+ ```bash
233
+ # Check only changes in PR
234
+ ace-git-secrets scan --branch feature-branch --since "$(git merge-base main feature-branch)"
235
+ ```
236
+
237
+ Remember: Your role is to **detect and report** security issues. For remediation actions (revoking tokens, rewriting history), direct users to follow the `token-remediation.wf.md` workflow instruction.
@@ -0,0 +1,27 @@
1
+ # Ruby Security Examples
2
+
3
+ This file provides Ruby-specific examples related to the main [Security Guide](../security.g.md).
4
+
5
+ * **Dependency Scanning:** `bundler-audit`, GitHub Dependabot/Security Alerts
6
+ * **Static Analysis (SAST):** `brakeman` (for Rails)
7
+ * **Input Validation:** ActiveModel validations (Rails), custom validation logic.
8
+ * **Secure Configuration:** Using environment variables, Rails credentials.
9
+
10
+ ```ruby
11
+ # Example: Secure file path handling (avoiding directory traversal)
12
+ require 'pathname'
13
+
14
+ BASE_DIR = Pathname.new('/safe/base/path').realpath
15
+
16
+ def read_user_file(user_input)
17
+ requested_path = BASE_DIR.join(user_input)
18
+
19
+ # Basic check (more robust checks might be needed)
20
+ unless requested_path.realpath.to_s.start_with?(BASE_DIR.to_s)
21
+ raise ArgumentError, "Invalid file path: #{user_input}"
22
+ end
23
+
24
+ # Proceed with reading requested_path if valid
25
+ File.read(requested_path)
26
+ end
27
+ ```
@@ -0,0 +1,51 @@
1
+ # Rust Security Examples
2
+
3
+ This file provides Rust-specific examples related to the main [Security Guide](../security.g.md).
4
+
5
+ * **Dependency Scanning:** `cargo audit`, GitHub Dependabot
6
+ * **Static Analysis (SAST):** `cargo clippy` (catches some security issues), potentially external SAST tools.
7
+ * **Input Validation:** Using Rust's type system, crates like `validator`.
8
+ * **Secure Configuration:** Environment variables, configuration files with restricted permissions, secrets management services.
9
+ * **Memory Safety:** Rust's core safety features prevent many common vulnerabilities (e.g., buffer overflows, use-after-free).
10
+
11
+ ```rust
12
+ use std::path::{Path, PathBuf};
13
+ use std::fs;
14
+ use std::io;
15
+
16
+ // Example: Secure file path handling
17
+ fn get_safe_path(base_dir: &Path, user_input: &str) -> io::Result<PathBuf> {
18
+ let joined_path = base_dir.join(user_input);
19
+ // Canonicalize resolves '..' and symlinks
20
+ let canonical_path = fs::canonicalize(&joined_path)?;
21
+
22
+ // Ensure the canonical path is still within the base directory
23
+ if canonical_path.starts_with(base_dir) {
24
+ Ok(canonical_path)
25
+ } else {
26
+ Err(io::Error::new(
27
+ io::ErrorKind::PermissionDenied,
28
+ format!("Path traversal attempt detected: {}", user_input),
29
+ ))
30
+ }
31
+ }
32
+
33
+ fn main() -> io::Result<()> {
34
+ let base = PathBuf::from("/safe/base/path");
35
+ // Simulate creating the directory if it doesn't exist for the example
36
+ // fs::create_dir_all(&base)?;
37
+
38
+ let user_input = "safe_file.txt";
39
+ match get_safe_path(&base, user_input) {
40
+ Ok(path) => println!("Accessing safe path: {:?}", path),
41
+ Err(e) => eprintln!("Error: {}", e),
42
+ }
43
+
44
+ let malicious_input = "../outside_file.txt";
45
+ match get_safe_path(&base, malicious_input) {
46
+ Ok(path) => println!("Accessing malicious path: {:?}", path),
47
+ Err(e) => eprintln!("Error: {}", e), // Should print PermissionDenied error
48
+ }
49
+ Ok(())
50
+ }
51
+ ```
@@ -0,0 +1,33 @@
1
+ # TypeScript Security Examples
2
+
3
+ This file provides TypeScript-specific examples related to the main [Security Guide](../security.g.md).
4
+
5
+ * **Dependency Scanning:** `npm audit`, `yarn audit`, Snyk, GitHub Dependabot
6
+ * **Static Analysis (SAST):** ESLint security plugins (e.g., `eslint-plugin-security`), SonarQube/SonarCloud
7
+ * **Input Validation:** Libraries like `zod`, `joi`, `class-validator`.
8
+ * **Secure Configuration:** Environment variables, secrets management services (e.g., AWS Secrets Manager, HashiCorp Vault).
9
+
10
+ ```typescript
11
+ import path from 'path';
12
+
13
+ // Example: Secure file path handling
14
+ const ALLOWED_BASE_DIR = path.resolve('/safe/base/path');
15
+
16
+ function getSafeFilePath(userInput: string): string {
17
+ const resolvedPath = path.resolve(path.join(ALLOWED_BASE_DIR, userInput));
18
+
19
+ // Check if the resolved path is still within the allowed directory
20
+ if (!resolvedPath.startsWith(ALLOWED_BASE_DIR)) {
21
+ throw new Error(`Invalid file path requested: ${userInput}`);
22
+ }
23
+ return resolvedPath;
24
+ }
25
+
26
+ // Example: Escaping output to prevent XSS (conceptual - use a library)
27
+ import { escape } from 'your-html-escaping-library';
28
+
29
+ function renderUserComment(comment: string): string {
30
+ const escapedComment = escape(comment);
31
+ return `<div class="comment">${escapedComment}</div>`;
32
+ }
33
+ ```