mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
feat: Deno.execPath() no longer requires --allow-read permission (#29620)
This commit changes `Deno.execPath()` API to no longer require read permission. This change is dictated by the fact that in common scenarios, requiring read permission is less secure than not requiring permissions - if a user wants to spawn a Deno subprocess using the current executable, they would do something like: ``` new Deno.Command(Deno.execPath(), { args: ["eval", "1+1"] }).outputSync(); ``` To run this program, currently one needs to pass `--allow-read --allow-run=deno` flags. It's possible to limit scope of `--allow-read` flag, but it's really cumbersome to do, so most users will opt to give a blanket `--allow-read` permission. Not requiring read permissions allows the above program to be run with just `--allow-run=deno` flag. This change is in similar to relaxing of permissions in `Deno.cwd()` API done in https://github.com/denoland/deno/pull/27192. Ref https://github.com/denoland/deno/issues/20061#issuecomment-2942497783
This commit is contained in:
parent
d4b02455df
commit
f781796402
3 changed files with 3 additions and 19 deletions
3
cli/tsc/dts/lib.deno.ns.d.ts
vendored
3
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -1591,9 +1591,6 @@ declare namespace Deno {
|
||||||
* console.log(Deno.execPath()); // e.g. "/home/alice/.local/bin/deno"
|
* console.log(Deno.execPath()); // e.g. "/home/alice/.local/bin/deno"
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission.
|
|
||||||
*
|
|
||||||
* @tags allow-read
|
|
||||||
* @category Runtime
|
* @category Runtime
|
||||||
*/
|
*/
|
||||||
export function execPath(): string;
|
export function execPath(): string;
|
||||||
|
|
|
@ -113,13 +113,10 @@ pub enum OsError {
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2(stack_trace)]
|
#[op2]
|
||||||
#[string]
|
#[string]
|
||||||
fn op_exec_path(state: &mut OpState) -> Result<String, OsError> {
|
fn op_exec_path() -> Result<String, OsError> {
|
||||||
let current_exe = env::current_exe().unwrap();
|
let current_exe = env::current_exe().unwrap();
|
||||||
state
|
|
||||||
.borrow_mut::<PermissionsContainer>()
|
|
||||||
.check_read_blind(¤t_exe, "exec_path", "Deno.execPath()")?;
|
|
||||||
// normalize path so it doesn't include '.' or '..' components
|
// normalize path so it doesn't include '.' or '..' components
|
||||||
let path = normalize_path(current_exe);
|
let path = normalize_path(current_exe);
|
||||||
|
|
||||||
|
|
|
@ -184,20 +184,10 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Deno.test({ permissions: { read: true } }, function execPath() {
|
Deno.test({ permissions: { read: false } }, function execPath() {
|
||||||
assertNotEquals(Deno.execPath(), "");
|
assertNotEquals(Deno.execPath(), "");
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({ permissions: { read: false } }, function execPathPerm() {
|
|
||||||
assertThrows(
|
|
||||||
() => {
|
|
||||||
Deno.execPath();
|
|
||||||
},
|
|
||||||
Deno.errors.NotCapable,
|
|
||||||
"Requires read access to <exec_path>, run again with the --allow-read flag",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test(
|
Deno.test(
|
||||||
{
|
{
|
||||||
ignore: Deno.build.os !== "linux",
|
ignore: Deno.build.os !== "linux",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue