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

オープン
#28 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
cli, security

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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).

主要言語
Python
スター
1
フォーク
4
平均マージ
12日 21時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

alphacrack/python-maithili-dsl のほかの issue

alphacrack/python-maithili-dsl の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。