Skip to content

feat(cli/args): implement --deny-import flag #29702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sgasho
Copy link
Contributor

@sgasho sgasho commented Jun 11, 2025

Closes: #29502

Preparing deny_import.js like below,

import "https://deno.land/std@0.201.0/log/mod.ts";
console.log("hello");

I verified that these changes were working properly by running the following command: ~/denoland/deno/target/debug/deno run --deny-import="example.com:443,deno.land:443" deny_import.js shows an import access error like the one below.

スクリーンショット 2025-06-12 0 01 29

I also verified that ~/denoland/deno/target/debug/deno run --deny-import="example.com:443" deny_import.js does not show any errors because example.com is not referenced in deny_import.js

スクリーンショット 2025-06-12 0 03 27

Comment on lines +4096 to +4107
.arg(
{
let mut arg = deny_import_arg().hide(true);
if let Some(requires) = requires {
// allow this for install --global
if requires != "global" {
arg = arg.requires(requires)
}
}
arg
}
)
Copy link

@anonhostpi anonhostpi Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ANNOTATION: simply a clone of the allow_import_arg behavior from the lines above it:

deno/cli/args/flags.rs

Lines 4084 to 4095 in 724685c

.arg(
{
let mut arg = allow_import_arg().hide(true);
if let Some(requires) = requires {
// allow this for install --global
if requires != "global" {
arg = arg.requires(requires)
}
}
arg
}
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deny_import_arg behavior is a bit different from allow_import_arg.

Do you mean that I should extract line 4099-4104 as a method?

Or, am I missing something...

Copy link

@anonhostpi anonhostpi Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No just commenting on the diff. The behavior here wasn't exactly obvious and highlighed well by the diff.

If you were curious, I initially didn't understand the // allow ... comment until I looked at the undiffed file and realized it was a copy and paste.

@bartlomieju bartlomieju added this to the 2.4.0 milestone Jun 16, 2025
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.

Missing flag --deny-import
3 participants