Should CI/CD Pipelines Automatically Fix Hardcoded Secrets?

March 20, 2026 5 answers
Asked by CuriousCoder42
I've been trying a new method for handling secrets in CI/CD pipelines using Python's AST (Abstract Syntax Tree) instead of usual regex approaches. Typically, detection of hardcoded secrets is done, but fixing them remains a manual effort. My goal is to see if we can automate the remediation process for common safe cases directly in the CI pipelines. Here's what my experimental tool does: - It scans Python repositories for hardcoded secrets. - It analyzes assignment statements using Python's AST. - It replaces detected secrets with environment variable references if the change is structurally safe. - If the safety of the change can't be assured, it leaves the file intact and just reports the finding. For instance, it transforms: SENDGRID_API_KEY = "SG.live-abc123xyz987" into: SENDGRID_API_KEY = os.environ["SENDGRID_API_KEY"] But it won't attempt to change something like: token = "Bearer " + "sk-live-abc123" I'm mainly looking for insights on these points: - Should CI support automatic remediation for hardcoded secrets? - Or should it only handle detection and leave fixes to developers? - Are there teams already practicing automated fixes like this in their workflows? I'm interested in hearing how others navigate this issue in real CI pipelines.

Answers

TechWhiz92
Clever approach using AST! It avoids false positive headaches that regex often brings. Most teams I worked with prefer a CI that blocks potential issues instead of automatically rewriting codeโ€”better to catch than to guess! The safety in your transformations means you might save a ton of time, as long as itโ€™s all guaranteed to be safe.

CodeCraftsman123: Exactly! It's a delicate balance, and proving that the transformation is safe is key before trusting it in CI.

Reply to this answer
AppSecGuru35
I donโ€™t support CI pipelines modifying code automatically. It'd be better as a pre-commit hook instead. That way, developers can stay in control of their changes.

DevOpsExplorer10: Yeah, that's the path I'm leaning towards too. CI changing code feels like a huge risk. Pre-commit hooks are much more trustworthy since they handle changes locally.

Reply to this answer
DevOpsNinja93
Iโ€™m against tools making direct changes in the CI environment. It's safer to create a merge request for review instead. That way, you've got oversight on any changes being made.

CodeSavant77: Totally agree! Giving tools that kind of power feels risky. Merging changes with a suggested fix seems like the best compromise. Do you think teams are actually adopting this approach, or is it still mostly manual fixes after a build fails?

Reply to this answer
PythonPal88
Using AST for secret detection is smart! Regex canโ€™t keep up and often leads to too many false positives. Iโ€™d suggest running your tool as a pre-commit hook rather than relying on it in CIโ€”itโ€™ll catch issues earlier in the dev cycle. Have you considered expanding support for other types of assignments, like kwargs?

SecureScript62: Pre-commit seems like the better way to go, less overhead in CI. As for kwargs or attributes, thatโ€™s tricky! Iโ€™m trying to be cautious and only tackle the simplest cases right now.

Reply to this answer
CodeGuardian1
Been in AppSec for a while, and while your method has lower noise, be aware of the coverage gaps. There are always config files or YAMLs where secrets can sometimes hide, which need to be covered too.

SecretSeeker28: True, coverage is crucial. Right now, my tool is focused mainly on handling safe cases in Python, since expanding into YAML or Terraform could overcomplicate things.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions