Skip to content

SK-3018-gitleaks-detection-fix-added-automated-script-to-fix-generate… - #346

Merged
skyflow-himanshupal merged 4 commits into
mainfrom
himanshupal/SK-3018-gitleaks-detection-multiple-secret-exposures-identified-across-repository-skyflow-node
Sep 24, 2026
Merged

skyflow-himanshupal merged 4 commits into
mainfrom
himanshupal/SK-3018-gitleaks-detection-multiple-secret-exposures-identified-across-repository-skyflow-node

Conversation

@skyflow-himanshupal

@skyflow-himanshupal skyflow-himanshupal commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fern regenerates src/_generated_ from scratch, so realistic-looking example secrets in its JSDoc comments (a fake JWT, fake token UUIDs) keep re-triggering gitleaks on every regen. Hand-fixing them doesn't stick.
This PR adds automated detection, redaction, and enforcement so this stops being a recurring manual chore.

What's included

  • scripts/patch-generated-secrets.js — runs the real gitleaks binary against Rule/gitleaks.toml and auto-redacts whatever it flags inside src/_generated_, rather than hand-maintaining a list of known-bad
    strings. Redacts by position (not by the matched text itself) so it can't corrupt surrounding quotes, self-tests the local gitleaks build before trusting it, verifies with tsc --noEmit, and rolls back cleanly on
    any failure.
  • .githooks/pre-commit — two-tier local guard: tier 1 runs the script above and stages only what it actually redacted (plus whatever you'd already staged); tier 2 runs gitleaks protect --staged and blocks the
    commit on anything left over.
  • .github/workflows/gitleaks-auto-redact.yml (new) — runs the same auto-redaction on every PR push and commits the fix straight back to the branch. Closes the gap for contributors without gitleaks/node
    installed locally.
  • .github/workflows/Gitleaks.yml — now actually fails the check when it finds something, instead of only commenting on the PR.
  • Manually redacted the fake JWT/token examples already present in the generated auth and token clients.

Testing

  • Verified end-to-end against real and scratch repos: redaction, rollback, self-test, and idempotency all pass.
  • Confirmed the local hook no longer sweeps unrelated working-tree changes into a commit.
  • Confirmed CI now blocks on real findings and self-heals once the auto-redact commit lands.

@github-actions

Copy link
Copy Markdown

✅ Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions

Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

Comment thread scripts/patch-generated-secrets.js Fixed
@github-actions

Copy link
Copy Markdown

✅ Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions

Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate issues affect secret detection, failure handling, and staging safety.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Adds automated gitleaks redaction and verification for generated code, integrating it into pre-commit workflows.

Changes:

  • Adds redaction and TypeScript verification.
  • Registers npm scripts for redaction and hook setup.
  • Adds two-tier pre-commit secret scanning.
File Summary Findings
scripts/​patch-generated-secrets.js Detects, redacts, compiles, and verifies generated code. Line 248 — Moderate (3 votes): Final-scan failures can leave overwritten files un restored and stage unverified edits.
package.json Registers redaction and hook setup scripts. None recorded.
.githooks/​pre-commit Runs redaction and staged gitleaks scanning. Line 48 — Critical (1 vote): Missing gitleaks allows commits containing secrets, and CI does not block findings.
Line 46 — Moderate (2 votes): Unconditionally stages all working-tree changes, including unrelated or incomplete changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .githooks/pre-commit
Comment thread .githooks/pre-commit Outdated
Comment thread scripts/patch-generated-secrets.js Outdated
@github-actions

Copy link
Copy Markdown

✅ Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions

Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

@github-actions

Copy link
Copy Markdown

✅ Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions

Copy link
Copy Markdown

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

@skyflow-himanshupal
skyflow-himanshupal merged commit 0c8a2d4 into main Sep 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants