-
Notifications
You must be signed in to change notification settings - Fork 0
Auto Fix Engine
PenumbraForge edited this page Mar 29, 2026
·
1 revision
Gate doesn't just find secrets -- it fixes them. The auto-fix engine extracts secrets to .env files and rewrites source code to use environment variable references.
gate fix # Fix all findings
gate fix --dry-run # Preview changes without writing
gate fix --interactive # Fix one at a time
gate fix --undo # Restore from snapshot- Snapshot -- backs up all files that will be modified
-
Extract -- writes each secret value to a
.envfile with a derived variable name - Rewrite -- replaces the secret in source with the appropriate env var reference
-
Import -- adds necessary import statements (
require('dotenv'),import os, etc.) -
Protect -- adds
.envto.gitignoreif not already present - Verify -- re-scans modified files to confirm secrets are gone
| Language | Env Var Reference | Import Added |
|---|---|---|
| JavaScript/TypeScript | process.env.VAR_NAME |
require('dotenv').config() |
| Python | os.environ['VAR_NAME'] |
import os |
| Go | os.Getenv("VAR_NAME") |
"os" import |
| Ruby | ENV['VAR_NAME'] |
require 'dotenv/load' |
| Java | System.getenv("VAR_NAME") |
None needed |
| YAML | ${VAR_NAME} |
None needed |
| Terraform | var.var_name |
Variable block added |
| Dockerfile | ${VAR_NAME} |
None needed |
| JSON | Extract only (manual migration) | N/A |
Gate generates .env variable names from the rule ID and surrounding code context:
stripe-live-secret → STRIPE_SECRET_KEY
aws-access-key-id → AWS_ACCESS_KEY_ID
mongodb-uri → MONGODB_URI
- Values containing special characters (
#,$, spaces, quotes) are automatically double-quoted and escaped - Existing
.envvalues are checked before writing -- duplicates are skipped, conflicts get a_NEWsuffix -
.envfile is created with0600permissions (owner-only read/write) - File permissions are preserved on modified source files (executables keep
+x)
When fixing multiple secrets in the same file, Gate processes findings bottom-up and tracks import insertions to prevent line number drift. If an import statement is added at the top of the file, remaining findings have their line numbers adjusted automatically.
If something goes wrong:
gate fix --undoThis restores all modified files from the snapshot created before fixing.