Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Predictable temp directory paths in pack management enable symlink attacks (CWE-377)

Aperta
#6,391 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
backend, security

Direzione di ricerca

Inizia in st2common/st2common/services/packs.py leggendo temp_backup_action_files, restore_temp_action_files e remove_temp_action_files, quindi esamina la creazione dei lock in st2common/st2common/util/pack_management.py. Sostituisci i percorsi temporanei prevedibili e il percorso del lock basato su /tmp con una gestione sicura, preservando il comportamento di backup, ripristino, rimozione e blocco dell’installazione dei pack. Il lavoro è completato quando queste operazioni non espongono più percorsi /tmp prevedibili ad attacchi tramite symlink o file di lock.

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

Descrizione

Summary

Pack management functions use hardcoded, predictable paths under /tmp/ with os.mkdir instead of tempfile.mkdtemp. This creates a TOCTOU (time-of-check-time-of-use) race condition where a local attacker can pre-create a symlink at the expected path, causing StackStorm to write pack files to an arbitrary location.

Affected Files

st2common/st2common/services/packs.py

Three functions use predictable temp paths:

# Line 426
def temp_backup_action_files(pack_base_path, metadata_file, entry_point, temp_sub_dir):
    temp_dir_path = "/tmp/%s" % temp_sub_dir
    os.mkdir(temp_dir_path)

# Line 450
def restore_temp_action_files(pack_base_path, metadata_file, entry_point, temp_sub_dir):
    temp_dir_path = "/tmp/%s" % temp_sub_dir

# Line 468
def remove_temp_action_files(temp_sub_dir):
    temp_dir_path = "/tmp/%s" % temp_sub_dir
    if os.path.isdir(temp_dir_path):
        shutil.rmtree(temp_dir_path)
st2common/st2common/util/pack_management.py
# Line 120-123
temp_dir_name = hashlib.md5(
    pack_url.encode(), **hashlib_kwargs
).hexdigest()
lock_file = LockFile("/tmp/%s" % (temp_dir_name))

The lock file path is derived from an MD5 hash of the pack URL, which is predictable and not collision-resistant.

Impact

A local attacker with write access to /tmp/ can:

  1. Symlink attack on temp_backup_action_files: Pre-create a symlink at the expected path before os.mkdir is called. If the symlink points to a directory the attacker controls, pack files will be written there, potentially leaking sensitive configuration or entry point code.

  2. Symlink attack on restore_temp_action_files: Replace the temp directory with a symlink pointing to attacker-controlled content. When StackStorm restores from the "backup," it copies the attacker's files into the pack directory, achieving arbitrary code execution via a malicious entry point.

  3. Lock file manipulation: The predictable lock file path allows an attacker to pre-create the lock file, causing a denial of service (pack installations hang waiting for the lock), or to delete the lock file to cause concurrent pack installations to race.

Recommended Fix

Use tempfile.mkdtemp for all temporary directories:

import tempfile

# Instead of:
temp_dir_path = "/tmp/%s" % temp_sub_dir
os.mkdir(temp_dir_path)

# Use:
temp_dir_path = tempfile.mkdtemp(prefix="st2_pack_backup_")

For the lock file, use a directory under StackStorm's control (e.g., /opt/stackstorm/locks/) rather than /tmp/.

References

  • CWE-377: Insecure Temporary File
  • CWE-362: Race Condition (TOCTOU)
  • Discovered via manual code review
Lingua principale
Python
Stelle
6.5k
Fork
792
Merge medio
1g 3h
PR unite (30g)
4

Preparare l'ambiente

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 StackStorm/st2

Tutte le issue di StackStorm/st2

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.