You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SECURITY] allow ignoring files to prevent secrets being leaked from .env to LLM #539
Forgive me if I've missed it, but I couldn't see any mechanism in the code for ignoring files like .env which very often contain API secrets and other credentials and sensitive data.
If I'm right, that means that currently it's possible for security-critical data to be leaked to the LLM, which would be a pretty significant security concern. Other agentic coding environments have gone through the same pain, e.g. there are many threads such as this one in the Cursor forums. So it would be great if opencode got this right from early on.
I think it's fairly simple to solve: just support an .opencodeignore file at the top of the repo (and perhaps honour .gitignore by default too).
(On a related but tangential note, ideally everyone would standardise on .ai-ignore, .ai-rules etc. rather than every agent having its own set of config files, but that's a battle for another day ...)
See google-gemini/gemini-cli#2092 for a report of a similar issue there (although Gemini CLI does at least already respect .gitignore by default). Some approaches to the solution are also suggested in that issue.
It reads my entire user directory without a hitch. Is this not a little worrisome? One thing is secrets like encryption, - and API keys, another thing entirely is personal medical documents and whatnot. Would it be possible to implement some sort of whitelist functionality where you explicitly state what folders/files are accessible?
It reads my entire user directory without a hitch. Is this not a little worrisome? One thing is secrets like encryption, - and API keys, another thing entirely is personal medical documents and whatnot. Would it be possible to implement some sort of whitelist functionality where you explicitly state what folders/files are accessible?
If preventing opencode from reading sensitive files requires the user to go through any process more than an extremely simple configuration task (e.g. adding a file to .ai-ignore), then I don't think the feature can reasonably be considered as implemented. For example, while supporting more sophisticated control via plugins is awesome, if the user is required to write code, then it's an inherently insecure design by default.
I would strongly recommend making ignoring .env part of the default configuration. It's a very well-known industry-wide convention these days that this file typically contains secrets, so feeding those secrets to LLMs by default is really not at all good practice.
Reacted by TheTerrasque, Aiden Cline, Martin Imre, superDuperCyberTechno, eggp, Josip Delić, Pieter, Benja Tillyer, Mitchell Wallace, François Rouault and 12 more
agent is locked to cwd by default (can't use read or edit tools on files outside)
It can however, still use shell commands outside the CWD. Would it be feasible to just neuter opencode completely outside the CWD with options to open up its permissions if need be?
agent is locked to cwd by default (can't use read or edit tools on files outside)
It can however, still use shell commands outside the CWD. Would it be feasible to just neuter opencode completely outside the CWD with options to open up its permissions if need be?
While this is an important topic, and certainly requires attention, I think it belongs in a separate issue, because in the vast majority of cases .env will be inside the CWD.
@aspiers I will say the llm can't grep for this files but I think we may also want to add extra preventions by default in the read tool too. Thanks for pushing back on this a bit!
On version 0.15.13 just had grok-code-fast-1 unashamedly read and modify my .env without warning. This doesn't seem to have blocked reading or editing files named .env
OpenCode already supports.ignore files, but it's not blocking, for example, the read tool or grep tool from reading from those files.
You can check this plugin, https://github.com/lgladysz/opencode-ignore which extends some blocking functionalities for those tools except the bash tool, so, for example, Agent can read a file through the cat command. Gemini CLI is not blocking that, though.
Kinda concerning that a tool like OpenCode does not have these safeguards by default.
I totally agree, but unfortunately even tools that have a deny setting sometimes find a way to circumvent this... (they act like humans 😆)
E.g., Claude Code in my case tried several times, and then found a way to overwrite the .env using the Bash tool and piping a new env var with > instead of >>.
Similar things happened to me with Gemini CLI and other agents. I found no tool so far that I would to some extent trust concerning "confident" or "secure" secret handling. With OpenCode I yesterday had to rotate a bunch of API keys (nothing bad to do) because it created an .env.example file and wanted to test it by copying its file with placeholder values to .env 😁 Nobody is to blame for this except me, but it's at least good to know that these things still happen (and that the plugin solution from the docs also does not handle this). I have also explicitly denied access in the agents file, and in the memories, but it's clear that I can just hope that this is being followed, and have to ask the bot to follow the rules from time to time (just like with a human coworker 🤭).
Probably using an MCP server for your vault is the best solution at the moment.
Or has anyone found a better solution for local development? Maybe the bots just want to educate us not to use dotenv files at all (but then there are products that still expect plain-text secrets in their MCP settings 😭🤣🤷).
I implemented this and it's working like a charm! I suspect the sandbox from anthropic would be a better approach but for now, opencode can't read or modify any file in my .codeignore. If this doesn't get implemented I could open a PR.
@PhillipAWells thats sounds like a very tricky request that won't meet strickt regulations because once the agent can read the file it means that the secrets inside were broadcasted to the model.
This was a short term solution, long term we want you to be able to define granular permissions for any tool and override defaults everywhere so everything can be exactly how you'd like it.
It would prolly look similar to bash tool but for read you'd be able to do something like:
Activity
aspiers commentedon Jun 29, 2025
See google-gemini/gemini-cli#2092 for a report of a similar issue there (although Gemini CLI does at least already respect
.gitignoreby default). Some approaches to the solution are also suggested in that issue.aspiers commentedon Jun 29, 2025
Also anthropics/claude-code#79
thdxr commentedon Jun 29, 2025
our ls tool should be reworked to use
rgwhich respects gitgnore - i'll do thisaspiers commentedon Jun 29, 2025
Thanks @thdxr this sounds like a great step in the right direction!
superDuperCyberTechno commentedon Jul 11, 2025
It reads my entire user directory without a hitch. Is this not a little worrisome? One thing is secrets like encryption, - and API keys, another thing entirely is personal medical documents and whatnot. Would it be possible to implement some sort of whitelist functionality where you explicitly state what folders/files are accessible?
SeanRoberts commentedon Jul 12, 2025
I created a separate issue for that here
In the meantime I'll just use it within a container.
rekram1-node commentedon Aug 14, 2025
A few improvements have been shipped in this area list of improvements:
aspiers commentedon Aug 14, 2025
My $0.02:
If preventing opencode from reading sensitive files requires the user to go through any process more than an extremely simple configuration task (e.g. adding a file to
.ai-ignore), then I don't think the feature can reasonably be considered as implemented. For example, while supporting more sophisticated control via plugins is awesome, if the user is required to write code, then it's an inherently insecure design by default.I would strongly recommend making ignoring
.envpart of the default configuration. It's a very well-known industry-wide convention these days that this file typically contains secrets, so feeding those secrets to LLMs by default is really not at all good practice.rekram1-node commentedon Aug 14, 2025
definitely fair point about .env I tend to agree w/ you there
superDuperCyberTechno commentedon Aug 15, 2025
It can however, still use shell commands outside the CWD. Would it be feasible to just neuter
opencodecompletely outside the CWD with options to open up its permissions if need be?aspiers commentedon Aug 15, 2025
While this is an important topic, and certainly requires attention, I think it belongs in a separate issue, because in the vast majority of cases
.envwill be inside the CWD.rekram1-node commentedon Aug 15, 2025
@aspiers I will say the llm can't grep for this files but I think we may also want to add extra preventions by default in the read tool too. Thanks for pushing back on this a bit!
fkukuck commentedon Sep 25, 2025
.envfile being ignore fixed with ff1f4d6?mitchell-wallace commentedon Oct 22, 2025
On version 0.15.13 just had grok-code-fast-1 unashamedly read and modify my .env without warning. This doesn't seem to have blocked reading or editing files named .env
3 remaining items
betolink commentedon Nov 11, 2025
I think this is a must feature, along with a more fine grained control on what tools and directories the agents can use.
JosXa commentedon Nov 12, 2025
We would appreciate .aiignore support!
lgladysz commentedon Nov 12, 2025
OpenCode already supports
.ignorefiles, but it's not blocking, for example, the read tool or grep tool from reading from those files.You can check this plugin, https://github.com/lgladysz/opencode-ignore which extends some blocking functionalities for those tools except the bash tool, so, for example, Agent can read a file through the
catcommand. Gemini CLI is not blocking that, though.raymelon commentedon Nov 13, 2025
Fell into this just now. #4308
Kinda concerning that a tool like OpenCode does not have these safeguards by default.
redtux commentedon Nov 14, 2025
I totally agree, but unfortunately even tools that have a deny setting sometimes find a way to circumvent this... (they act like humans 😆)
E.g., Claude Code in my case tried several times, and then found a way to overwrite the
.envusing the Bash tool and piping a new env var with>instead of>>.Similar things happened to me with Gemini CLI and other agents. I found no tool so far that I would to some extent trust concerning "confident" or "secure" secret handling. With OpenCode I yesterday had to rotate a bunch of API keys (nothing bad to do) because it created an
.env.examplefile and wanted to test it by copying its file with placeholder values to.env😁 Nobody is to blame for this except me, but it's at least good to know that these things still happen (and that the plugin solution from the docs also does not handle this). I have also explicitly denied access in the agents file, and in the memories, but it's clear that I can just hope that this is being followed, and have to ask the bot to follow the rules from time to time (just like with a human coworker 🤭).Probably using an MCP server for your vault is the best solution at the moment.
Or has anyone found a better solution for local development? Maybe the bots just want to educate us not to use dotenv files at all (but then there are products that still expect plain-text secrets in their MCP settings 😭🤣🤷).
betolink commentedon Nov 14, 2025
I implemented this and it's working like a charm! I suspect the sandbox from anthropic would be a better approach but for now, opencode can't read or modify any file in my .codeignore. If this doesn't get implemented I could open a PR.
lgladysz commentedon Nov 14, 2025
@betolink What about Grep content in ignored files?
Also file should be named
.ignorelike in docs https://opencode.ai/docs/tools/#ignore-patternslgladysz commentedon Nov 16, 2025
@rekram1-node isn't this fixed with 4c2e888 in v1.0.66?
rekram1-node commentedon Nov 16, 2025
Yeah I think this covers it
PhillipAWells commentedon Nov 17, 2025
This is a good security feature, but is there a way to whitelist a
.envfile?It is sometimes necessary for the agent to check the file in order to ensure that certain variables are being set properly.
drorata commentedon Nov 17, 2025
@PhillipAWells thats sounds like a very tricky request that won't meet strickt regulations because once the agent can read the file it means that the secrets inside were broadcasted to the model.
rekram1-node commentedon Nov 17, 2025
This was a short term solution, long term we want you to be able to define granular permissions for any tool and override defaults everywhere so everything can be exactly how you'd like it.
It would prolly look similar to bash tool but for read you'd be able to do something like:
read:
".env*": "allow"
But the default would be current behavior
feat: add C++ language support and hook tests (anomalyco#539)
fix(app): scope identities by workspace URL and ID (anomalyco#539)