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

Đang mở
#28 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
50/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
cli, security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
1
Fork
4
Merge trung bình
12 ngày 21 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của alphacrack/python-maithili-dsl

Tất cả issue của alphacrack/python-maithili-dsl

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.