[HARDENING] _validate_imports misses non-line-start imports — switch to AST-based validation

Aperta
#28 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
cli, security

Direzione di ricerca

Start with _validate_imports in maithili_dsl/cli.py, which matches imports by line prefix, and reproduce the miss with x = 1; import os. Read CONTRIBUTING.md, since changes to the sandbox require a Security Considerations section in the PR. Replace the line scan with an ast.parse() walk over ast.Import and ast.ImportFrom nodes, and add a SyntaxError path. Done when the semicolon, indented, and from ... import cases are rejected in tests/test_security.py and existing tests still pass.

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

Descrizione

area:cli P2 quality security

File: maithili_dsl/cli.py (_validate_imports)

The pre-exec import check is line-prefix-based (stripped.startswith('import ')), so statements not at the start of a line are missed:

x = 1; import os     # passes _validate_imports (verified)

Runtime is still guarded by the __import__ wrapper, so this is not a sandbox escape — only whitelisted modules load either way — but it silently defeats the documented "raw Python imports are rejected before execution" layer, and prefix matching will also miss conditional/indented imports.

Fix: parse with ast.parse() and walk ast.Import / ast.ImportFrom nodes instead of scanning lines. Bonus: this also gives precise line numbers for error messages, and a clean SyntaxError path for malformed code before exec.

Tests: semicolon repro above, indented import inside यदि, from os import path variants — all in tests/test_security.py (per CONTRIBUTING.md this touches the sandbox, so a Security Considerations section is required in the PR).

Lingua principale
Python
Stelle
1
Fork
4
Merge medio
12g 21h
PR unite (30g)
1

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 alphacrack/python-maithili-dsl

Tutte le issue di alphacrack/python-maithili-dsl

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.