Skip to content

Check for secrets before commit and push - #102

Merged
nasser1941 merged 1 commit into
mainfrom
feat/secret-check
Oct 10, 2026
Merged

nasser1941 merged 1 commit into
mainfrom
feat/secret-check

Conversation

@nasser1941

Copy link
Copy Markdown
Owner

Closes #94.

In the dahua session, a model committed a camera password in source code, as the default configuration, and pushed it to a public repository. Nothing warned anyone. Cleaning up took a history rewrite and a force-push, and GitHub still serves the old commits.

What changes

  • lcode.secretscan, before a git commit or git push the model runs, scans what would enter the history:
    • Commit: the staged lines it adds, plus what a git add in the same command would stage, including untracked files. -a adds the unstaged tracked changes.
    • Push: every commit of the branch that no remote has yet, with the commit named in the finding.
    • Nested commands: inside quotes (bash -c "git add . && git commit …", sh -c, eval), lcode can't tell what would be staged, so it scans everything that could be.
  • What it finds:
    • passwords, keys and tokens written as literal values;
    • in configuration files (.env, YAML, INI, TOML…), unquoted values too;
    • credentials in URLs (rtsp://admin:…@);
    • private keys, and tokens with a known form: GitHub, GitLab, AWS, Slack, OpenAI and Anthropic, Google, JWT, xAI, Hugging Face, Stripe;
    • .env files, but not .env.example.
  • Not secrets: placeholders (CHANGE_ME, your_password, <token>, ${VAR}, …), references (os.environ[…], args.password, paths, URLs), names about a secret (token_url, password_file, max_password_length), and obviously fake values (example, dummy, test…). The report shows file:line with the value masked: cam.py:5: a password or key: "password": "Xk…".
  • Then:
    • ask mode: you decide, through a permission prompt of kind secret; programs get it via approve.
    • auto-edit and yolo: the command doesn't run, and the model is told to read the secret from the environment or a git-ignored config, and to ask the user if it isn't a secret.
    • /commit and /pr: the findings are shown before you confirm; /pr asks "Push anyway?".
    • GitHub Action: it doesn't commit or push. Its comment names file:line without any part of the value.
  • Allowing a line: lcode: allow-secret (or gitleaks:allow) in a comment; secret_check = false turns the check off.
  • Docs: usage ("Secrets in commits"), configuration, automation (the secret kind), and the CHANGELOG.
  • Tests: the git_repo and github fixtures moved from test_gitflow.py to conftest.py, so test_secretscan.py can use them too.

Tests

tests/test_secretscan.py, 31 tests:

  • secrets found and placeholders left alone;
  • diff parsing with files, lines and commits;
  • which commands commit or push, nested ones included;
  • in a real git repository:
    • git add x && git commit, staged changes, and -a;
    • a push to a bare remote, before and after the commits are there;
  • the agent:
    • yolo blocks the commit;
    • ask mode goes to approve as secret;
    • secret_check = false lets it through;
  • /pr declines to push;
  • the action's report has no excerpts.

Real checks

  • qwen3.6-35b in yolo mode, asked to "Create cam.py with a DEFAULTS dict … password Xk9pq72z … Then commit it with git":
    • the commit was stopped: cam.py:5: a password or key: "password": "Xk…";
    • nothing was committed;
    • the model stopped and asked whether to use a placeholder with an environment variable, or ignore the file.
  • On lcode's own repository: this branch's own diff is clean. Every tracked file gives 8 findings, all intentional fixtures in lcode's own secret-detection tests. Only added lines are scanned, so they matter only if those lines change.
  • gitleaks on the branch's commit: no findings. The test's fake xAI key is built from parts.

🤖 Generated with Claude Code

Before the model runs git commit or git push, scan what it would add to
the history: the lines a commit adds (including what a git add in the
same command stages) or the commits a push sends. Passwords, keys and
tokens in code or configuration, credentials in URLs, private keys,
known token forms and .env files are reported with file and line.

In ask mode the user decides; in auto-edit and yolo the command doesn't
run and the model is told to move the secret out of the code. /commit
and /pr show the findings before confirming, and the GitHub Action
doesn't commit at all. "lcode: allow-secret" in a comment allows a line;
secret_check = false turns it off.

Closes #94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nasser1941
nasser1941 merged commit b0e0d90 into main Oct 10, 2026
12 checks passed
@nasser1941
nasser1941 deleted the feat/secret-check branch October 10, 2026 16:56
This was referenced Oct 10, 2026
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.

Check for secrets before commit and push

1 participant