Replies: 5 comments
|
this looks like expected behavior tbh.
the blog post is a different story — it clearly shows toObject() working with --allow-env=SOME_SECRET and returning a filtered object. So either that was the actual behavior back in 2.6 and something changed, or the blog post is just wrong. Might be worth opening a separate docs issue for that |
|
Building on @felipeinf's answer about the blog post being off: I'm fairly sure the apparent filtering in the 2.6 post is a side effect of how the example is launched, not a real permission narrowing. That example invokes the script with a shell prefix like So the permission model is consistent: For one-off access: const pwd = Deno.env.get("PWD"); // works with --allow-env=PWDWorth opening a docs issue on the 2.6 post so the example is clearer about what the shell prefix is doing vs what the permission is doing. |
|
This is a reported regression / behavior change in Deno 2.7.x, not user error. The Deno blog post you referenced uses an older permission prompt format; in recent versions, The technical reason
This is different from What you're seeing vs. what the blog promisedThe blog example from Deno 2.6: $ SOME_SECRET=foo deno run --allow-env=SOME_SECRET main.ts
{ SOME_SECRET: "foo" }This worked because Workaround: iterate the allowlist manuallyIf you need const ALLOWED = ["PWD", "HOME", "USER"] as const;
function envToObject(): Record<string, string> {
const env: Record<string, string> = {};
for (const key of ALLOWED) {
const val = Deno.env.get(key);
if (val !== undefined) env[key] = val;
}
return env;
}
console.log(envToObject());Run with: deno run --allow-env=PWD,HOME,USER main.tsThis never triggers the wide permission prompt because each If you really need the full
|
|
When you run Deno with a scoped permission like How to resolve:
|
|
Since I've been messing with it a ton recently, here's what I found works: |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Version
Deno 2.7.12
Repro Code
index.ts:Run with:
Or replace
PWDwith other valid env var.Actual Result
Permission system requests wide environment variable access.
Expected Result
Deno just reads the allowed environment variables, permission system does not request for more.
Notes
The official Deno blog post for Deno 2.6 shows a similar example:
Did I misunderstood or missed something? Is that an expected behavior?
All reactions