nodejs / nodejs/node

fs.glob (async and sync) returns no matches when `--allow-fs-read` is used

Aperta
#61,499 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

confirmed-bug permission
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

Version

22.22.1 (22.x), 24.14.0 (24.x), 25.8.1 (25.x)

Platform
Linux louiellan-IdeaPad-3-15ITL6 6.14.0-37-generic #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem

fs, permission

What steps will reproduce the bug?

Create the file

sample1.js

const fs = require('fs')
console.log(fs.globSync('somedir/*'));

Directory Structure

somedir
|--> file1.js
sample1.js

Run the following commands:

node --permission --allow-fs-read=somedir/ ./sample1.js
How often does it reproduce? Is there a required condition?

The bug consistently reproduces if the --allow-fs-read is given a specific directory such as somedir/, but not with the allow all *

What is the expected behavior? Why is that the expected behavior?
  1. fs.globSync should return matches as it has a read access to that given directory
  2. asynchronous fs.glob (also from node:fs/promises) returns matches to that given directory

Code snippet for checking fs.glob working as intended
sample2.js
(works just fine - for comparison)

const fsPromise = require('fs/promises'); 
(async () => {
for await (const entry of fsPromise.glob('somedir/*')) {
    console.log(entry);
}})();

sample3.js
(works just fine - for comparison)

const fs = require('node:fs');
fs.glob('somedir/*', (err, matches) => {
    if (err) throw err;
    console.log(matches);
});

Running the files

node --permission --allow-fs-read=somedir/ ./sample2.js
node --permission --allow-fs-read=somedir/ ./sample3.js
What do you see instead?

Empty matches

[]
Additional information

came across this when @RafaelGSS suggested to include permission model tests while using glob on --watch-path
Refs: https://github.com/nodejs/node/pull/59478

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione di sample1.js e confronta la sua chiamata a fs.globSync con gli esempi funzionanti di fs/promises.glob e fs.glob basato su callback sotto --permission --allow-fs-read=somedir/. Traccia la gestione dei permessi di glob e aggiungi un test di regressione per una directory autorizzata specificamente; il lavoro è completato quando glob sincrono e asincrono restituiscono somedir/file1.js invece di un array vuoto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
backend, security
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
64/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.