Deno read access to CWD
Asked Answered
B

2

9

How can I allow read access to CWD (current working directory) used by Deno.cwd()?
I want explicit permission only for CWD. I don't want to allow every read with plain --allow-read flag.

I've tried to pass CWD as a parameter but it doesn't work.

deno run --allow-read=CWD index.ts
Uncaught PermissionDenied: read access to <CWD>, run again with the --allow-read flag

Index.ts is just:

console.log(Deno.cwd());

I am using deno 1.2.0.

Bonhomie answered 23/7, 2020 at 10:8 Comment(4)
What about deno run --allow-read=. index.ts ?Barytes
@Barytes It works but it also allows to read any file in currently working directory. It is better than allow to read anything but if there is any solution which grants access only to cwd() (or any other way to get cwd path) I would be much happier.Bonhomie
As your command is working while reproducing it, I saw there are granularity options. Is there access like writing happening or reading outside of cwd, that could prevent the execution?Shote
@Shote Not sure what you mean but currently there is only Deno.cwd() in index.ts but I will need to use --allow-access for different files. Something like --allow-access=path/to/file,another/path,cwd.Bonhomie
A
2

That actually depends on the OS you are using.

In Windows, you can use

deno run --allow-read=%cd% index.ts

In Ubuntu bash

deno run --allow-read=$PWD index.ts

Abdication answered 5/8, 2020 at 18:43 Comment(0)
B
8
deno run --allow-read=./ index.ts

The relative route ./ will allow you to access everything inside the folder in which index.ts is in. Best practices however are to use more fine-grained/specific permissions

As pointed out before https://deno.land/manual/getting_started/permissions#permissions-allow-list

Bedfast answered 3/8, 2020 at 19:54 Comment(0)
A
2

That actually depends on the OS you are using.

In Windows, you can use

deno run --allow-read=%cd% index.ts

In Ubuntu bash

deno run --allow-read=$PWD index.ts

Abdication answered 5/8, 2020 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.