[BUG] async writeFileAtomic() writes the previous file's mode and owner into the caller's options object
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
- Ambito
- backend
Direzione di ricerca
Inizia da writeFileAsync() e confronta il modo in cui gestisce le opzioni del chiamante con writeFileSync(), che prima le copia. Riproduci il problema scrivendo due file con modalità diverse e riutilizzando lo stesso oggetto delle opzioni. Il lavoro è completato quando ogni file mantiene la propria modalità e il proprio proprietario e l’oggetto delle opzioni del chiamante rimane invariato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
The async writeFileAtomic() fills in options.mode and options.chown from the existing file by assigning them on the options object the caller passed in. If the same object is used again for a second file, the second file gets the first file's mode and owner instead of keeping its own. A 0600 file can become 0644 this way. writeFileAtomic.sync() copies the object first and does not have this problem.
Expected Behavior
Each call takes the mode and owner from its own target file, as the README says ("If mode is not specified, it will default to using the permissions from an existing file"), and the caller's options object is not changed.
Steps To Reproduce
// repro.js
const fs = require('fs')
const writeFileAtomic = require('write-file-atomic')
fs.writeFileSync('public.txt', 'a', { mode: 0o644 })
fs.writeFileSync('secret.txt', 'b', { mode: 0o600 })
const options = { encoding: 'utf8' }
;(async () => {
await writeFileAtomic('public.txt', 'hello', options)
await writeFileAtomic('secret.txt', 'token', options)
console.log((fs.statSync('secret.txt').mode & 0o777).toString(8))
console.log(options)
})()
umask 022; node repro.js
Actual:
644
{ encoding: 'utf8', mode: 33188, chown: { uid: 1010, gid: 1010 } }
Expected:
600
{ encoding: 'utf8' }
When run as root, the second file is also chowned to the first file's owner.
Environment
- write-file-atomic: 8.0.0 and main (23e111d)
- Node: 26.13.0
- OS: Debian 12, Linux 6.1
The cause is in writeFileAsync(), which assigns options.mode = stats.mode and options.chown = {...} directly, while writeFileSync() does options = Object.assign({}, options) first.
Credit: https://ucsbplse.github.io/
- Lingua principale
- JavaScript
- Stelle
- 256
- Fork
- 51
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/write-file-atomic
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 50/100
npm/write-file-atomic#243 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
npm/write-file-atomic#224 ·
-
PornographyAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 1/100
npm/write-file-atomic#189 · 6 reazioni ·
-
Bug Needs Triage
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
npm/write-file-atomic#163 ·
-
Reporting a vulnerabilityAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 35/100
npm/write-file-atomic#156 ·
Tutte le issue di npm/write-file-atomic
Issue simili
-
status: ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
melodic-software/claude-code-plugins#14389 ·
I maintainer di solito rispondono entro 1 giorno
-
启用「思考过程机器翻译」后,已配对的手机远控页面无法启动Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
Fei2411/DeepSeek-Bot#1194 ·