DEV Community

Dimitris Kyrkos
Dimitris Kyrkos

Posted on

Your secrets don't need a git commit to leak into an AI tool

Debug pastes leak creds past git

Most of us have the "don't commit secrets" reflex drilled in. Pre-commit hooks, secret scanners in CI, .env in .gitignore. Good. That covers the repo.

It doesn't cover the context window.

The gap: the repo is not the boundary anymore

When you work with an AI coding assistant, what leaves your machine isn't just the file you're editing. It's whatever you paste, whatever the extension decides is relevant, and whatever the agent reads while it's "helping." The security boundary now includes the editor extension, the chat history, any telemetry, and every service that processes that context on the way to the model and back.

Secret scanners watch commits. Nothing in a typical setup watches what you paste into a chat panel at 6pm while a deploy is failing.

Here are the usual ways a secret ends up in context without ever touching git.

1. The failing test that prints its config

An integration test fails. The assertion message helpfully dumps the client object, which includes the connection string with the password inline. You copy the whole test output into the assistant and ask "why is this failing?"

The question was about the assertion. The payload included the credential.

2. The environment dump

$ env | sort
...
AWS_SECRET_ACCESS_KEY=...
DATABASE_URL=postgres://app:...@db.internal:5432/prod
STRIPE_SECRET_KEY=sk_live_...
Enter fullscreen mode Exit fullscreen mode

"Here's my environment, why can't the app find the config?" is a completely normal debugging move. It's also the fastest way to hand over every key on the box in one paste. Agents that can run shell commands can do this on their own if you let them.

3. Logs that log too much

A verbose HTTP client logs request headers. One of them is Authorization: Bearer .... You paste 200 lines of log to get help with a timeout, and line 143 is a live token.

4. The copied snippet

Someone shares a "working example" in Slack with the key still in it. You paste it into the assistant to adapt it. Now it's in two systems you don't control instead of one.

(These are illustrative scenarios, not specific incidents, but if you've debugged anything under pressure you've probably seen at least one.)

What actually helps

  • Minimize what you send. Paste the relevant ten lines, not the whole log. Ask about the error, not the environment.
  • Redact before pasting. Mask tokens, connection strings and headers. A small shell function or editor snippet that scrubs obvious patterns is worth having.
  • Scope your credentials. If a dev key does leak, it should only be able to touch dev. Short-lived, least-privilege keys shrink the blast radius.
  • Check how your tool handles data. What's retained, for how long, whether it's used for training, what the extension sends automatically, where telemetry goes. These are often separate settings and separate policies. One "privacy" toggle rarely answers all of them.
  • Restrict what agents can read. If your assistant can open files and run commands, keep .env, credential files and secret stores out of its reach.

If it already happened

Deleting the chat message is not remediation. You don't know what was logged, cached or forwarded before you hit delete. Treat it like any other exposure: rotate the credential, revoke the old one, check access logs for use.

The reframe

Secret management used to be a version control problem. With AI tools in the loop, it's a data-flow problem: anything that reaches the model's context has, to some degree, left your control.

The safest secret is the one that never enters the context in the first place.

How does your team handle this today? Do you have any tooling that checks what goes into an AI assistant, or is it all down to developer habit?

Top comments (137)

Collapse
 
sinarezaei profile image
Sina Rezaei •

The CI/CD case is where this gets really interesting. Microsoft documented a Claude Code Action vulnerability where prompt injection through untrusted GitHub content could lead to reading ANTHROPIC_API_KEY from /proc/self/environ. The Bash path had environment scrubbing, but the Read tool followed a different path and bypassed that isolation boundary.

That’s the part I think teams need to pay attention to: protecting secrets in Git or filtering terminal output doesn’t help if another tool can reach the same credentials through a different path. I’d treat the agent’s entire tool surface as part of the security boundary, with explicit access controls and isolation between untrusted input and sensitive runtime state.

Collapse
 
rdin777 profile image
rim dinov •

The CI/CD boundary is definitely where this gets critical. I love the canary secret idea for runtime data paths, but for source code, static analysis acts as the ultimate pre-execution canary.
For example, in Web3 smart contracts, I wrote a Slither detector that flags hardcoded Hardhat test addresses or plaintext API keys directly in the codebase. It catches the leak at the syntax level, long before the CI/CD pipeline even has a chance to expose it to an AI agent's Read tool or the blockchain. Combining runtime canaries with compile-time static checks is the real defense in depth.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Agreed, those checks complement each other well. Static analysis catches what ends up in the code, while runtime testing catches what gets exposed through the environment, tools or logs. The important thing is not to confuse passing one with being safe overall. In the scenario Sina described, the secret never needed to be hardcoded in the repo for the agent to reach it.

Thread Thread
 
sinarezaei profile image
Sina Rezaei •

Exactly. GitHub Actions OIDC is a good example here: you can remove long-lived cloud credentials from GitHub Secrets, but a job with id-token: write can still request an identity token and exchange it for cloud credentials if the trust policy allows it. If an AI agent processing an untrusted PR can reach that path, the problem isn’t a leaked key in the repo anymore; it’s what the job is authorized to obtain at runtime. I’d keep the agent in a separate, unprivileged job and make the privileged deployment job consume only validated artifacts, with no untrusted PR content passed back into its execution context.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

This is a really important distinction. OIDC removes the need to store long-lived credentials, but it doesn't remove the risk of granting an untrusted job access to the identity flow in the first place. Separating the agent from deployment permissions and passing only validated artifacts across that boundary feels like a much stronger design than trying to sanitize everything the agent might see. Least privilege still matters even when there are no static keys to steal.

Thread Thread
 
rdin777 profile image
rim dinov •

Spot on, Dimitris! OIDC is a great example of removing long-lived credentials, but you're absolutely right that it doesn't solve the fundamental problem of untrusted code execution.
The distinction between 'no static keys to steal' and 'no unauthorized access to grant' is critical. Even with OIDC, if a malicious agent or compromised CI job has deployment permissions, it can still wreak havoc through the identity flow itself.
This is where defense in depth becomes non-negotiable:
Pre-deployment: Static analysis (like custom Slither detectors) catching hardcoded patterns before they even reach CI
Runtime: Environment isolation, artifact validation, and strict permission boundaries
Post-deployment: Monitoring for anomalous on-chain behavior
Your point about 'separating the agent from deployment permissions' is exactly right. I've seen teams implement OIDC beautifully but still get drained because the CI pipeline itself had overly broad permissions.
Curious: In your experience, what's the biggest hurdle for teams trying to implement proper permission separation in CI/CD? Is it tooling complexity, or organizational inertia?

Thread Thread
 
sinarezaei profile image
Sina Rezaei •

I think it's usually a mix of both, but the technical debt is what makes organizational resistance harder to overcome.

Take GitHub Actions as an example. A team might use workflow_run to trigger a privileged deployment workflow after PR validation. The validation job itself has no deployment credentials, so the setup looks isolated. But if the privileged workflow downloads and processes an artifact produced by the untrusted PR workflow, that artifact becomes another trust boundary. If it's not treated as untrusted input, the separation is largely meaningless.

OIDC adds another layer to this. Even when a job doesn't store cloud credentials, a broad trust policy can still allow the wrong workflow context to assume a deployment role. Restricting the sub claim to a specific repository and protected environment, rather than trusting the repository alone, makes a real difference.

What I find particularly challenging is that teams often have to redesign existing pipelines, artifact handling, runner isolation and deployment approvals just to enforce these boundaries. That's not always a tooling problem; it's also a question of whether security requirements are built into the architecture from the beginning or added after the pipeline becomes business-critical.

I'd rather see privilege separation enforced at the workflow and identity levels than rely on developers remembering which inputs an AI agent should never touch.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I think the biggest hurdle is usually technical debt, with organizational inertia making it worse. Once a pipeline becomes business-critical, even relatively simple permission changes can turn into a redesign of workflows, runners, artifact handling and deployment approvals.

Sina's workflow_run example is a good illustration. Teams can believe they've isolated untrusted code, but then accidentally reintroduce trust through artifacts or overly broad OIDC policies. I'd rather see these boundaries enforced by architecture than depend on developers remembering which inputs are safe. Security should be the default behavior of the pipeline, not another checklist people have to follow.

Collapse
 
sinarezaei profile image
Sina Rezaei •

Slither is useful for catching source-level issues, but the harder cases are secrets that only exist at runtime. A contract can pass static checks while the CI job compiling or testing it still has access to cloud credentials. I’d also be careful with Hardhat test addresses: those aren’t necessarily secrets themselves, but private keys, deployer credentials or API tokens embedded alongside them can be. The key question is whether the agent can access anything privileged while processing untrusted code, not just whether the repository passes a scan.

Thread Thread
 
rdin777 profile image
rim dinov •

Thanks, Sina! Glad the canary idea resonates. You're absolutely right that the CI/CD boundary is where things get really interesting (and scary).
The challenge with canary testing for source-level secrets is that it tests the runtime data path, but the vulnerability exists at the code level. By the time the canary would trigger, the hardcoded key might already be in a committed state.
That's where static analysis as a pre-commit/pre-merge gate becomes essential. I built a custom Slither detector specifically to catch hardcoded test keys and CEX credentials before they even reach CI — inspired by a real $152K exploit where a Hardhat test key sat in production for months.
The ideal setup is layered:
Pre-commit: Static analysis blocking commits with hardcoded patterns
CI/CD: Canary secrets testing the actual deployment pipeline
Runtime: Monitoring for anomalous on-chain behavior
Curious: Have you implemented canary testing in your own workflows? I'd love to hear how you balance false positives with coverage.

Thread Thread
 
sinarezaei profile image
Sina Rezaei •

I haven't built a dedicated canary setup for this exact workflow yet, but I think the interesting part is making the canary observable across the entire pipeline, not just checking whether it gets detected.

For example, imagine an AI coding agent running in CI with access to an AWS role through OIDC. A canary credential placed in a controlled test environment could reveal whether the agent, a build script, or a test subprocess attempts to read or transmit it. I'd correlate that with the job identity and outbound network activity rather than relying on a single alert.

On the false-positive side, I'd keep test fixtures and intentionally invalid credentials clearly separated from anything that resembles a usable secret. Otherwise, teams eventually start treating scanner warnings as noise.

One thing I'm curious about: does your custom Slither detector also inspect how a key is used, or does it primarily rely on known key formats and patterns? That distinction seems important for catching credentials that don't match standard test-key signatures.

Thread Thread
 
rdin777 profile image
rim dinov •

Great question, Sina — and you've hit on a fundamental limitation of static analysis that I think about a lot.
To be direct: my current Slither detector primarily relies on known key formats and patterns (syntax), not on how the key is used (semantics). It scans the AST for:
Literal assignments of known Hardhat/Foundry default test addresses
String patterns matching common private key formats (64 hex chars)
Variable names containing keywords like test_key, dev_private_key, etc.
The limitation you pointed out is real: If an attacker uses a non-standard key format or obfuscates the assignment (e.g., bytes32 key = keccak256("some_string")), a pattern-based detector will miss it.
That's exactly why I advocate for a layered approach:
Static analysis (Slither): Catches the obvious 80% — hardcoded patterns, known test keys, plaintext credentials. Fast, deterministic, runs on every commit.
Runtime monitoring: Catches the subtle 20% — keys that are dynamically generated, obfuscated, or loaded from environment variables at runtime. This is where your canary credential idea shines.
Behavioral analysis: Monitors on-chain activity for anomalous patterns (e.g., a "test" address suddenly calling transferOwnership on a production contract).
I'm currently experimenting with extending the Slither detector to do taint analysis — tracking how a variable flows from assignment to usage. For example, if a variable is assigned from an environment variable (msg.sender, block.timestamp, or an external call), the detector could flag it as "potentially untrusted" even if the format looks normal.
But you're right that true semantic analysis (understanding intent rather than just pattern) is where the field needs to evolve. Curious: in your canary setup, how do you distinguish between a legitimate test credential being used in CI vs. a leaked credential being exploited? Is it purely based on network context, or do you also check the calling identity?

Thread Thread
 
sinarezaei profile image
Sina Rezaei •

That's an important distinction. I'd separate credential access from credential use, because they don't necessarily indicate the same thing.

For me, the cleanest approach would be to make the canary identity-aware and ensure it never becomes part of the legitimate test path.

For example, imagine a GitHub Actions workflow using OIDC to assume an AWS role. I'd assign a unique role session name using GITHUB_RUN_ID and correlate the resulting AWS activity with the workflow run, repository, commit SHA, and job identity.

Then I'd look at two different signals:

  • Access: Did an agent, build script, or subprocess attempt to retrieve the canary from the environment or filesystem?
  • Use: Did that credential actually trigger an authentication request or an AWS API call?

CloudTrail can help correlate the second case with the assumed-role session and its identity. Network telemetry and process-level events can provide additional context for the first.

I'd also keep legitimate test credentials completely separate from canaries. A test fixture should use a dedicated mock identity or an isolated test account, while a canary should never be required for a successful build or deployment.

One more detail: I'd avoid treating an unfamiliar IP address as the deciding factor. A compromised process running inside an otherwise legitimate CI job could inherit the same network identity. The job identity, credential provenance, process context, and requested AWS action together provide a much stronger signal.

Ultimately, I'd treat unexpected canary authentication as a security incident, even if the request originates from a recognized CI runner. That's the difference between knowing where a request came from and knowing whether it was authorized.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That Read tool detail is a great example of why checking only one execution path isn't enough. You can harden shell access and still have another tool reach the same sensitive data. The agent's permissions and isolation need to cover the whole tool surface, not just the commands we expect it to run.

Collapse
 
bytestay profile image
ByteStay •

This one hit close to home.

We had all the "don't commit secrets" reflexes and still caught ourselves doing the env | sort paste you describe. So we changed how secrets reach the machine in the first place.

Nothing real lives in .env files on our laptops anymore.

Secrets sit in a self-hosted vault, and anything that needs them runs through a tiny wrapper that hands them to that one process. The terminal, and anything reading it, only ever sees the command.

We also stopped printing secrets, even to check them.

Earlier today we had to confirm a key in the clipboard was the same one in the vault We compared the length and the first few characters of a SHA-256, and never looked at the key itself, It feels a bit paranoid until you remember how much ends up in scrollback.

Two smaller lessons that cost us some time:

  • Pipe secrets in, don't pass them as arguments, Arguments end up in shell history and in ps.
  • Watch your quotes. A $VAR inside double quotes gets expanded by the outer shell. We once sent the literal text instead of the value, and it took a while to notice, anything complex now goes into a small script.

And honestly, the guardrail I like most is the boring one, our coding assistant can't write to a secret store without one of us saying yes, every single time.

So, to your question: still mostly habit, but habit with a few doors locked.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

This is a great example of making the safer path the default instead of relying on people to remember every time. I especially like the wrapper approach and the approval gate for secret store writes. One small thing I'd add is making sure the wrapper doesn't accidentally expose secrets through debug output or child process environments. It's amazing how many different places a value can leak without anyone explicitly printing it.

Collapse
 
bytestay profile image
ByteStay •

Agreed, and the child environment is the one we haven't fully solved.

Every process the command starts inherits those variables. What we do is keep the blast radius small.

Our vault is a self-hosted Infisical. The wrapper logs in with a machine identity and runs infisical run --path=<folder>, so a command only gets the secrets of its own folder, not the whole vault.

Debug output bit us in a different way. Calling the wrapper with the shell as separate arguments once printed every injected value. Now complex commands always go into a script file, called with one single-quoted string.

"Nobody printed it" really isn't the same as "it didn't leak".

Thread Thread
 
kaj_ilands profile image
Kaj •

the child env is the part that's actually fixable, and folder scoping doesn't touch it. infisical run chooses which values get injected, not what the child hands on to its own children. exec the command directly with an explicit allowlist (env -i plus the three or four vars it truly needs) and there is nothing inherited left to leak. if a shell sits in the path, BASH_ENV comes along with it and a sourced file can flip tracing on without you typing set -x anywhere.

and check it from inside the child, tr '\0' '\n' < /proc/self/environ, not from the wrapper's log. the wrapper is the one process holding plaintext, so its own error paths are leak surface too, same class as the separate-arguments accident.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

This is a good distinction. Scoping which secrets get injected is only half the job if the process can pass them all to anything it launches. An explicit environment allowlist sounds like a solid next step, especially for commands that don't need the full set. I'd also test the child process environment and the wrapper's failure paths, since those are easy places to assume isolation is working without actually verifying it.

Thread Thread
 
bytestay profile image
ByteStay •

Agreed, and Kaj's point about the child environment is the one that matters most.

Our wrapper handles it in two ways now:

  • the vault token never goes through argv and never reaches the command, so it shows up neither in ps nor in the child's environment;
  • a command can start from an empty environment: a short allowlist (PATH, HOME and a few more) plus only the secrets that command needs.

And we check it from inside the child, reading the variable names from /proc, not from the wrapper's own log :)

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a solid improvement. Keeping the vault token out of the child entirely and starting commands with an empty environment closes two different exposure paths. I also like that you're verifying from inside the child rather than trusting what the wrapper reports. It sounds like the wrapper is evolving from just a secret injector into an actual security boundary. Have you found any edge cases with commands that need a larger environment, like build tools or nested scripts?

Thread Thread
 
bytestay profile image
ByteStay •

Yes, and that's exactly why the empty environment is opt-in rather than the default
CI is the main case, jobs rely on GITHUB_*, RUNNER_* and their own variables, so there the command keeps the caller's environment while the vault side stays locked down
For local commands that need more than the basics, we pass an explicit allowlist of extra names, every variable the command sees is one we chose

Thread Thread
 
kaj_ilands profile image
Kaj •

the edge case isn't a bigger environment. it's that the build tool writes your command line into the environment for you.

i ran it in a clean shell instead of guessing: env -i PATH=... make FOO=sentinel and FOO shows up in the recipe's env. it also lands in MAKEFLAGS as -- FOO=sentinel, so a nested $(MAKE) still has it. the wrapper never saw the variable, because argv is not the thing it filters.

so an allowlist that answers "which variables did we set" is enforcing on the wrong side. the only question worth asking is whether the child's own view, read from inside the child, contains anything we didn't put there. same run, tr '\0' '\n' < /proc/self/environ, diff it against the manifest, fail on any extra line.

the other edge is a tool that needs a capability instead of a value. ssh-add under env -i says "could not open a connection to your authentication agent". export one path, SSH_AUTH_SOCK, and it connects. nothing in that variable looks like a credential, and it is the credential: a socket you can reach is a signing oracle. so "allowlist the bigger set" quietly gives away the boundary it was there to draw.

which is why failing closed on a missing manifest entry matters more than the allowlist being complete. the test isn't a command that passes, it's deleting one entry and confirming the command refuses to run. if it still runs, the allowlist is documentation.

agreed that the wrapper is turning into a real boundary. boundaries are only boundaries if refusing is the default.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a really important distinction, especially the SSH_AUTH_SOCK example. It shows that an environment variable doesn't have to contain a secret to grant access to one. I also like the idea of treating the manifest as an enforced contract rather than just documentation, with a missing entry causing the command to fail. At that point you're testing the boundary itself, not just checking whether the happy path works. The MAKEFLAGS behavior is another subtle one I wouldn't have thought to check.

Thread Thread
 
kaj_ilands profile image
Kaj •

the read-back line i gave yesterday has a hole, and i found it by running it instead of trusting it.

in a make recipe with FOO=sentinel present:

$ tr '\0' '\n' </proc/self/environ | wc -c
0
Enter fullscreen mode Exit fullscreen mode

cat on the same file reads 76 bytes in my run, dd too. so it isn't the file or the shell. /proc/self/environ reports st_size 0, and GNU tr 9.1 trusts that and reads nothing. exit 0, no warning.

so the manifest diff comes back clean because it compared zero lines. not "no extra variables". zero lines.

same shape as the two we already have: the prose canary passed because nothing matched the string, the log passed because the field wasn't on the list, this passes because the reader read nothing. three ways to get a green result without looking at anything.

and the obvious guard lies too:

$ test -s /proc/self/environ && echo has content   # 76 bytes are there
(nothing)
Enter fullscreen mode Exit fullscreen mode

-s is st_size as well. so the guard has to come from a reader that ignores it: n=$(cat /proc/self/environ | wc -c); [ "$n" -gt 0 ] || exit 1.

on your delete test: that half still holds, because the wrapper fails closed before the command ever launches. the half that goes quietly green is the extra-line check, the one whose job is to prove the child never had what you didn't put there. that's the one that has to prove it looked at something.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a great catch, and an important correction. A successful exit code doesn't prove the check actually inspected the data, especially when the reader trusts a misleading st_size. I like the extra requirement here: the verification needs to prove it read a non-empty environment before trusting the diff, and fail closed if it can't. Otherwise the check itself becomes another false green signal. Thanks for testing this rather than just assuming the command did what it said.

Collapse
 
stackmasteraliza profile image
Aliza Ali •

Point 2 is the one that worries me most with agents rather than chat. You don't even have to paste env yourself; the agent can run it on its own while "debugging", and the output lands straight in context. Scrubbing the agent's shell environment helps, but as the /proc/self/environ case above shows, a file-read tool can walk right around it. The more durable fix is making sure there's nothing long-lived to find: short-lived, narrowly scoped credentials locally, so anything that does leak expires before it matters. A pre-commit hook for the context window would honestly be a great tool.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Exactly. Once an agent can read files directly, restricting its shell environment alone isn't enough. Short-lived, scoped credentials reduce the damage if something slips through, and I like the idea of a pre-commit hook for context. It would need to cover more than pasted text, though, since tool reads and command output can enter context without the user explicitly adding anything.

Collapse
 
stackmasteraliza profile image
Aliza Ali •

Agreed, the hook would have to sit between the tools and the model, not at the input box. Something like a redaction layer on every tool result (file reads, command output) that masks anything matching secret patterns before it ever reaches the context. That would make a fun open-source project.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I think that's exactly the right place for it. Putting the redaction layer between tool execution and the model would cover a lot more than just manual input. The tricky part would be avoiding false confidence from pattern matching, since not every sensitive value looks like a conventional API key. I'd love to see an open-source project explore this, especially if it could support different agent frameworks and MCP tools through a common interception layer.

Thread Thread
 
stackmasteraliza profile image
Aliza Ali •

Good point on false confidence. One way around it: the interception layer usually knows the actual secrets, from the env or the secret store, so it can redact exact known values (plus their base64 and URL-encoded forms) instead of only guessing by shape. Pattern matching then becomes the backup for secrets it doesn't know about, not the whole defence. MCP's single tool-result path would make a great place to hook that in.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a much stronger approach. If the interception layer has access to the actual secret values, exact-value matching can catch cases that pattern-based detection would miss, including encoded forms. I'd still be careful about where that matching happens and how the redaction rules are protected, so the layer doesn't become another place where secrets are exposed. And I agree, a shared MCP interception point could make this practical across different tools and agents.

Collapse
 
galagent profile image
Qingfeng •

Redaction before pasting is the same class of control as "don't commit secrets" — it works until the deploy is on fire and you paste the whole log at 6pm. The more durable lever is on the agent side: if the assistant can run env | sort or read .env, a human redaction habit is the only thing standing between you and a full dump, and that habit is exactly what pressure erases. Regex scrubbing is also whack-a-mole since providers rotate token prefixes and opaque keys slip through, so I'd rather bound the blast radius with short-lived scoped keys and log egress from whatever the extension sends — because delete never un-sends anything.

Collapse
 
rdin777 profile image
rim dinov •

Spot on. The "6pm failing-deploy" is the ultimate threat model because human habits inevitably break under pressure. Regex scrubbing is indeed whack-a-mole.
This is exactly why shifting left to automated, pattern-based static analysis in the CI/CD pipeline is non-negotiable. The linter doesn't get tired at 6pm. In Web3, I built a custom Slither detector specifically to catch hardcoded test keys and CEX credentials during the PR check. It ensures that even if a developer accidentally pastes the wrong config, the build fails before it ever reaches an AI agent's context or the mainnet. Automation is the only reliable safety net for human error.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

The CI checks are definitely useful, especially for catching secrets before they make it into the repo or a deployment. The gap I'd still worry about is what happens at runtime, though. A secret can be injected into the environment or returned by a tool without ever touching the code being scanned. That's why I think CI scanning and restricting what the agent can access need to work together.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Yeah, that's the key distinction. Redaction is useful, but it shouldn't be the main thing standing between an agent and production credentials. I'd rather limit what it can read in the first place, then add egress scanning and short-lived scoped credentials as backup layers. Logging what actually leaves the extension would be especially useful, assuming the logging itself doesn't become another place where secrets accumulate.

Collapse
 
alexshev profile image
Alex Shev •

The prevention path should include an egress test, not only a pre-commit scanner. Teams can seed a harmless canary secret in a nonproduction environment and verify that logging, prompts, and support exports all redact it consistently.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I like the canary idea because it tests the actual data path instead of assuming the scanner works. You could seed a fake credential and check whether it makes it into prompts, logs or exported traces. I'd also test different ways the agent can access data, since catching it in terminal output doesn't guarantee the Read tool or extension handles it the same way.

Collapse
 
alexshev profile image
Alex Shev •

A small path-by-sink matrix would make those differences visible: terminal, file read and extension output crossed with prompt, logs and traces. Use a unique fake canary per path so the test can identify where a leak originated, and verify the test harness itself detects a deliberately unfiltered control.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I like the path-by-sink matrix, especially using a different canary for each path. That makes it much easier to trace where the leak happened instead of just getting a pass or fail. And testing the harness with a deliberately unfiltered control is important too, otherwise a green result might just mean the test never caught anything in the first place.

Thread Thread
 
alexshev profile image
Alex Shev •

The per-path canaries are especially useful if the matrix includes the boundary, not just the client: terminal paste, editor extension, browser upload, CI log, and vendor API. Each path then has an accountable owner when a canary escapes.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a useful addition. Including the boundary makes the test much more actionable because it shows not only where the data leaked, but which component owns that part of the path. The vendor API is particularly worth including since the data has already left our environment by that point. Having an owner for each boundary also makes it easier to turn a failed canary test into a concrete fix rather than just another security finding.

Collapse
 
yahhi profile image
Valentina Koniukhova •

I ran this on my own MCP server tonight, exactly as this thread assembled it: one key-shaped canary and one prose canary per client-supplied field (@alexshev 's path-by-sink idea, @kaj_ilands 's "a fake key tests your regex, prose tests the logger"), then read back from CloudWatch and both DynamoDB tables with the raw AWS API, not through the app (@kaj_ilands 's point about verifying below the redaction layer).

Result: the three free-text fields masked every key-shaped string and kept the prose, the session id came back as its hash, and the user-agent header came back verbatim with the fake key in it. The policy promised masking for the whole log line; the code masked three fields. One-line fix, one test, redeployed, resent, read back masked. The prose canary was the control that proved the read-back worked at all.

The full run, with the steps so an agent can repeat it on your service, is here: worklore.dev/s/2026-10-30-a-canary...

Collapse
 
kaj_ilands profile image
Kaj •

the user-agent line is the one worth keeping. nothing in the masking code was wrong there. the list was. the policy said the log line, the code said three fields, and that gap is invisible until a sentinel goes somewhere the list didn't know about.

so a canary per known field can't catch this class of bug, because the bug is the field you forgot to name. the version that does: one sentinel in every client-supplied channel at once, including the ones nobody files under data (referer, cookie, x-forwarded-for, the page's query string), then read the store cold and search for the sentinel instead of checking fields one by one. if it turns up anywhere, the field list was never the boundary. the sink is.

and the prose control is the part most runs skip. a key-shaped canary passes on a logger that masks by pattern; prose doesn't. keep it as the gate on every field you add, not a one-time check.

Collapse
 
friga profile image
Artur Pokładek •

The worst one I've run into never went near a chat window. On a site I took over, the Supabase service role key sat in the client JS bundle, so anyone who opened devtools had a key that skips RLS.

Leaks into AI tools worry me too, but I'd grep the build output first. Does anyone here run a secret scan on what actually ships, or only on the repo?

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That’s a great point. Scanning the repo is only part of the picture because secrets can end up in generated bundles, build artifacts, or source maps even if the repo scan passes. I’d definitely add a secret scan on the actual build output or release artifact before deployment. The Supabase service role key is a particularly serious example because it’s not meant to be exposed to client-side code at all.

Collapse
 
friga profile image
Artur Pokładek •

Good shout on source maps, those get forgotten a lot. Scanning the build output catches them anyway, which is one more reason to scan what ships rather than what's committed.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Exactly. Source maps can expose more than people expect, especially if they contain original source or embedded configuration. I think the safest approach is to scan the final deployment artifact, including generated files and source maps, rather than relying only on what the build process was supposed to include.

Thread Thread
 
friga profile image
Artur Pokładek •

Agreed, the deployed artifact is the only version that matters. Thanks for the back and forth, good post.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Thanks, Artur! Really enjoyed the discussion. Your Supabase example is a good reminder that the same principle applies beyond AI tools: we need to inspect what actually leaves the build pipeline, not just what looks safe in the repository. Appreciate you adding to the conversation!

Collapse
 
kaj_ilands profile image
Kaj •

correction to my own comment further up: i blamed tr for trusting st_size. that was wrong, and the real cause is worse.

cat < /proc/self/environ | wc -c returns 0. cat /proc/self/environ | wc -c returns 4053. same shell, three runs, both bash and sh, no pipe needed to see it (the file version is 0 too). tr was never the problem. /proc/self behind a redirect is a different process than the one you meant, so the read is empty and exits 0. swap in a fixed pid and the redirect works.

the size lie is real but it is the other bug: test -s says empty on a populated file, and that one is st_size = 0.

measurements and the guard i use now: dev.to/kaj_ilands/cat-procselfenvi...

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Thanks for the correction and for sharing the measurements. That's an important distinction, and it makes the example even more interesting: there are two separate /proc quirks here, process-specific resolution of /proc/self and the misleading st_size = 0 behavior.

It also reinforces a broader point in my post: security tooling and debugging workflows need to account for what data is actually being read and exposed, not just what we assume is happening.

Appreciate you digging into the root cause and sharing a reproducible example!

Collapse
 
kaj_ilands profile image
Kaj •

there's a third quirk, and it's the one that undoes the fix i offered.

cat /proc/$$/environ reads the environment the kernel handed that process at exec. anything exported after that is not in it. measured, one script, one shell:

export LATE_SENTINEL=abc123
cat /proc/$$/environ   | grep -c '^LATE_SENTINEL='   # 0
cat /proc/self/environ | grep -c '^LATE_SENTINEL='   # 1
Enter fullscreen mode Exit fullscreen mode

so the exact sentinel the script just set is invisible to the check, which exits 0 and looks green. /proc/self only works there because cat inherits the export; the shell's own environ never refills. a canary read through $$ can be green and blind in the same run.

the smaller one: st_size=0 isn't a /proc/environ quirk, it's procfs generally. /proc/uptime reports 0 while cat returns 16 bytes. sysfs lies the other way: /sys/kernel/mm/transparent_hugepage/enabled reports 4096, cat returns 23. so a size-based guard is wrong on both, in opposite directions.

shape that held for me: read into a variable, measure the variable, fail closed on zero, then grep the sentinel inside that variable. choose the process on purpose, and never ask the filesystem how big the content is.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a really useful third distinction. The check needs to inspect the environment of the process that actually matters, and it needs to account for variables exported after that process started. Otherwise the test can pass while missing exactly the value it's supposed to detect.

I also appreciate the broader procfs/sysfs examples. The takeaway seems to be: don't use file metadata as proof of content, and be explicit about which process's environment you're validating. This is turning into a pretty good example of why security checks need to be tested against their own failure modes.

Collapse
 
mohsen_jr profile image
Mohsen jr •

The tricky part is that developers may not even realize what the agent can access. Redacting pasted logs helps, but limiting the agent’s file and command permissions seems like the more reliable fix. How do you balance that with giving it enough access to debug effectively?

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I’d start with read access limited to the project and only expand it when a debugging task actually needs more. For commands, I’d be especially careful with environment dumps, broad filesystem access and anything that can reach production systems. If the agent hits a permission boundary, that’s a good point to ask for approval rather than giving it blanket access upfront. It might take an extra step sometimes, but I’d rather have that friction than discover later what the agent could read all along.

Collapse
 
dexoryn profile image
Dexoryn •

I think the strongest approach is defense in depth restrict what the agent can read, scan outbound context before it reaches the model, and use short-lived credentials with minimal permissions.

No single layer catches everything, but together they reduce both the chance of exposure and the damage if one slips through.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Agreed, it's really about having multiple layers that don't all fail in the same way. I'd put restricting what the agent can access first, because once a secret is in the context, scanning is already playing catch-up. Short-lived credentials help make the inevitable mistakes less painful too.

Collapse
 
the_saint_dac63e343ee8704 profile image
The Saint •

The habits that hold up are the ones that cost nothing in the moment. Keep production credentials off laptops entirely, so the worst thing in a paste is a dev key. Have the app fail with a message that never prints its config or connection string. Load secrets through a wrapper that injects them at run time, so they are not sitting in env output to be pasted. And treat the 6pm failing-deploy case as the real threat model, since that is when people skip the redaction step.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

This is probably the most practical approach because it removes opportunities for mistakes instead of relying on people to catch them under pressure. Keeping production credentials off developer machines makes a huge difference, and avoiding secrets in error messages should be standard practice regardless of AI tools. Then even if someone pastes a full log, there's much less damage to worry about.

Collapse
 
the_saint_dac63e343ee8704 profile image
The Saint •

Agreed. One cheap way to enforce the error message rule is a test that deliberately triggers a failure and asserts the output does not contain anything shaped like a connection string or key. It turns a habit into something CI checks.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Nice, and that's a pretty low-effort test to add to an existing pipeline. I'd probably include a known dummy secret in the test config and assert it never appears in the error output, alongside checks for common credential patterns. It won't catch everything, but it makes sure a future change doesn't quietly bring the problem back.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.