embed: updating a named profile resets its file mode from 0600 to 0644

Aperta Adatta ai principianti
#7,053 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
80/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
security

Direzione di ricerca

Inizia da hindsight-embed/hindsight_embed/profile_manager.py, in particolare da ProfileManager.create_profile() e dal percorso di sostituzione atomica; poi leggi il ramo profile set-env in hindsight_embed/cli.py. Aggiungi test di regressione POSIX per la creazione di un profilo e la riscrittura di un profilo 0600 esistente con umask 022. Il lavoro è completato quando entrambe le operazioni mantengono i permessi a 0600 o più restrittivi, preservando la sostituzione atomica.

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

Descrizione

core

Version

hindsight-embed 1.3.0 was found in the local uv cache; the same write path is present in the cached package, the v1.3.0 source, and main at c828c7e41527d0c4916cac0ba2b56334fed4a79d. The exact executable used in the original CLI run was not captured.

Environment

macOS (Apple Silicon), with @vectorize-io/hindsight-coding-agents 0.9.0 using serverMode: "daemon", apiPort: 9077, and daemonProfile: "coding-agent". The daemon was uvx [email protected] --idle-timeout 0 --port 9077. The named profile stores HINDSIGHT_API_LLM_API_KEY in plaintext; the value is omitted. The profile's provider was opencode-go. The mode regression can be checked with a test profile and a placeholder value, without running a daemon or using a real key.

Steps to reproduce

On macOS, with an existing named profile (the observed run used coding-agent):

profile="$HOME/.hindsight/profiles/coding-agent.env"
chmod 600 "$profile"
stat -f '%Sp' "$profile"
hindsight-embed profile set-env coding-agent HINDSIGHT_API_LLM_PROVIDER opencode-go
stat -f '%Sp' "$profile"

Expected

The profile remains 0600 after the update. A new profile should default to 0600; rewrites should also preserve any stricter existing mode.

Actual

The mode changed from -rw------- (0600) to -rw-r--r-- (0644) after profile set-env. This was observed more than once. On the affected machine ~/.hindsight was 0700, which blocks other local users from traversing to the file; no unauthorized read was observed. The file-level restriction had still been lost.

Evidence

  • The set-env branch in hindsight_embed/cli.py reads the current profile, updates the requested key, then calls ProfileManager.create_profile().
  • ProfileManager.create_profile() in v1.3.0 writes the full profile via Path.write_text() to a per-process temp path, then calls Path.replace(). Current main swaps it through replace_file(), with the same mode behavior. Neither path copies the destination mode or sets a restrictive mode on the temp file. A fresh temp file takes the normal creation mode filtered by umask (0644 with umask 022), and the replacement retains the temp file's mode.
  • A later read-only stat found the profile back at 0600 and confirmed the parent directory was 0700. The update was not rerun during verification; the mode transition above is from the original reproduction.

Suggested fix

Keep the atomic replacement, but create the temp file with permissions no broader than 0600 before writing any profile values. If the existing file has a stricter mode, keep that stricter mode on replacement. Add POSIX regression coverage for both creating a profile and rewriting an existing 0600 profile under umask 022.

Lingua principale
Python
Stelle
45.2k
Fork
5.9k
Merge medio
5h 57m
PR unite (30g)
351

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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.

Altre issue di vectorize-io/hindsight

Tutte le issue di vectorize-io/hindsight

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.