Skip to content
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

Experimental Permissions: Checks from fs functions that accept Buffers fail with TypeError #54100

Closed
alistairjevans opened this issue Jul 29, 2024 · 7 comments · Fixed by #54104
Labels
confirmed-bug Issues with confirmed bugs. permission Issues and PRs related to the Permission Model

Comments

@alistairjevans
Copy link

alistairjevans commented Jul 29, 2024

Version

v22.5.1

Platform

Linux e0c5ff99f631 6.9.8-orbstack-00170-g7b4100b7ced4 #1 SMP Thu Jul 11 03:32:20 UTC 2024 aarch64 GNU/Linux

Subsystem

File system

What steps will reproduce the bug?

I saw this directly when when attempting a recursive delete. E.g.

script.js:

const fs = require('fs');
const pathBuffer = Buffer.from('/tmp/.mydir');
await fs.promises.rm(pathBuffer, { recursive: true })

Execute this with something like node --experimental-permission --allow-fs-write /tmp* script.js

How often does it reproduce? Is there a required condition?

This always happens provided the experimental-permission flag is set.

What is the expected behavior? Why is that the expected behavior?

Expected behaviour is that the permissions checking code allows a Buffer to be provided containing the path.

What do you see instead?

Error:

TypeError: The "reference" argument must be of type string. Received an instance of Buffer
    at Object.has (node:internal/process/permission:25:7)
    at lstat (node:fs:1551:45)
    at _rimraf (node:internal/fs/rimraf:67:3)
    at rimraf (node:internal/fs/rimraf:46:3)
    at node:internal/fs/rimraf:145:7
    at Array.forEach (<anonymous>)
    at node:internal/fs/rimraf:142:5
    at FSReqCallback.oncomplete (node:fs:187:23) {
  code: 'ERR_INVALID_ARG_TYPE'

From the looks of it, the code in .has that calls validateString needs to permit buffers as well for the reference argument.

Additional information

No response

@kevinuehara
Copy link
Contributor

So the problem happens only when pass the flag --experimental-permission? In previous versions is this happens normally?

@alistairjevans
Copy link
Author

Yes, only with --experimental-permission; that triggers the code path that checks the reference value. I haven't tested older versions, but to be honest the code is pretty clear that it mandates a string argument, I guess it just wasn't tested with callers that provide the path as a Buffer.

@kevinuehara
Copy link
Contributor

So a think this is an improvement... I can test and see if this error occurred in older versions. But anyway I will validate and see if I can improve and resolve with PR.

@alistairjevans
Copy link
Author

alistairjevans commented Jul 29, 2024

Ah, sorry, I wasn't trying to state that this is a regression, I think this is just a part of the still-in-development experimental permissions work, thought I'd flag it.

@kevinuehara
Copy link
Contributor

Aah ok! But thank you to sinalize! Someone can answer this question and if it is already under development, otherwise I can help with the contribution ❤️

@alistairjevans
Copy link
Author

alistairjevans commented Jul 29, 2024

I think @RafaelGSS is the man to talk to, based on the commit history.

@RafaelGSS
Copy link
Member

Apparently, this is caused by #52135. I will work on that.

@RafaelGSS RafaelGSS added confirmed-bug Issues with confirmed bugs. permission Issues and PRs related to the Permission Model labels Jul 29, 2024
nodejs-github-bot pushed a commit that referenced this issue Aug 3, 2024
PR-URL: #54104
Fixes: #54100
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
targos pushed a commit that referenced this issue Aug 14, 2024
PR-URL: #54104
Fixes: #54100
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
targos pushed a commit that referenced this issue Sep 21, 2024
PR-URL: #54104
Fixes: #54100
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
targos pushed a commit that referenced this issue Oct 2, 2024
PR-URL: #54104
Fixes: #54100
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. permission Issues and PRs related to the Permission Model
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants