Skip to content

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

Closed
@alistairjevans

Description

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

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.permissionIssues and PRs related to the Permission Model

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions