@@ -586,6 +586,98 @@ Then run with just `-P`:
586586$ deno run -P main.ts
587587```
588588
589+ ### Allow, deny, and ignore
590+
591+ For finer control over permissions, you can use the object form with ` allow ` ,
592+ ` deny ` , and ` ignore ` keys. This is especially useful when you need more granular
593+ permission control than simple boolean or array values provide.
594+
595+ #### Object form syntax
596+
597+ Instead of specifying a permission as a boolean or array:
598+
599+ ``` jsonc
600+ {
601+ " permissions" : {
602+ " default" : {
603+ " read" : true , // Simple boolean form
604+ " write" : [" ./data" ] // Simple array form
605+ }
606+ }
607+ }
608+ ```
609+
610+ You can use the object form:
611+
612+ ``` jsonc
613+ {
614+ " permissions" : {
615+ " default" : {
616+ " read" : {
617+ " allow" : [" ./data" , " ./config" ],
618+ " deny" : [" ./data/secrets" ],
619+ " ignore" : [" ./data/cache" ]
620+ },
621+ " write" : {
622+ " allow" : [" ./output" ],
623+ " deny" : [" ./output/system" ]
624+ }
625+ }
626+ }
627+ }
628+ ```
629+
630+ #### Available permissions
631+
632+ The ` allow ` , ` deny ` , and ` ignore ` keys work differently depending on the
633+ permission type:
634+
635+ - ** ` read ` and ` env ` ** : Support ` allow ` , ` deny ` , and ` ignore `
636+ - ** ` write ` , ` net ` , ` run ` , ` ffi ` , ` sys ` , and ` import ` ** : Support ` allow ` and
637+ ` deny ` (but not ` ignore ` )
638+
639+ #### Behavior
640+
641+ - ** ` allow ` ** : Explicitly grant access to specific resources. Can be ` true ` (to
642+ allow all), ` false ` (to allow none), or an array of specific paths/values to
643+ allow.
644+ - ** ` deny ` ** : Explicitly deny access (throw
645+ [ PermissionDenied] ( https://docs.deno.com/api/deno/~/Deno.errors.PermissionDenied ) )
646+ to specific resources, even if they would otherwise be allowed. Can be ` true `
647+ (to deny all), ` false ` (to deny none), or an array of specific paths/values to
648+ deny.
649+ - ** ` ignore ` ** : (Only for ` read ` and ` env ` permissions) Silently ignore access
650+ attempts to specific resources without throwing errors. Can be ` true ` ,
651+ ` false ` , or an array of specific paths/values to ignore.
652+
653+ #### Example
654+
655+ ``` jsonc
656+ {
657+ " permissions" : {
658+ " default" : {
659+ // Allow reading from data directory, but deny access to secrets
660+ // and silently ignore cache files
661+ " read" : {
662+ " allow" : [" ./data" ],
663+ " deny" : [" ./data/secrets" ],
664+ " ignore" : [" ./data/cache" ]
665+ },
666+ // Allow all environment variables except API keys
667+ " env" : {
668+ " allow" : true ,
669+ " ignore" : [" API_KEY" , " SECRET_TOKEN" ]
670+ },
671+ // Allow all, but deny 'rm', 'sudo'
672+ " run" : {
673+ " allow" : true ,
674+ " deny" : [" rm" , " sudo" ]
675+ }
676+ }
677+ }
678+ }
679+ ```
680+
589681### Test, bench, and compile permissions
590682
591683Permissions can be optionally specified within the ` "test" ` , ` "bench" ` , or
@@ -656,7 +748,14 @@ If you're ok with this risk, then this feature will be useful for you.
656748 },
657749 "permissions" : {
658750 "default" : {
659- "read" : [" ./src/testdata/" ]
751+ "read" : {
752+ "allow" : [" ./src/" ],
753+ "deny" : [" ./src/secrets/" ]
754+ },
755+ "env" : {
756+ "allow" : true ,
757+ "ignore" : [" TEMP_*" ]
758+ }
660759 }
661760 },
662761 "lint" : {
0 commit comments