Skip to content

security: Harden codebase against Shell and Eval injection vulnerabilities#507

Open
GiGiKoneti wants to merge 9 commits into
FOSSEE:masterfrom
GiGiKoneti:fix/security-p1-shell-injection-nghdl
Open

security: Harden codebase against Shell and Eval injection vulnerabilities#507
GiGiKoneti wants to merge 9 commits into
FOSSEE:masterfrom
GiGiKoneti:fix/security-p1-shell-injection-nghdl

Conversation

@GiGiKoneti
Copy link
Copy Markdown
Contributor

Security Audit & Hardening: Shell Injection and Eval Injection

This PR addresses critical vulnerabilities identified during a systemic security audit of the eSim codebase.

Vulnerabilities Fixed:

  1. Arbitrary Code Execution via eval() in plot_window.py (Custom Formulas)

    • Issue: The custom plotting formula input utilized raw eval() on user inputs, allowing malicious execution of file I/O, process execution, etc.
    • Resolution: Replaced raw eval() with a robust, custom AST (Abstract Syntax Tree) expression parser that only permits safe, predefined arithmetic operations and exact mathematical function wrappers (np.sin, np.cos, np.log, etc.). It safely parses parentheses-inclusive trace names like v(out) using placeholder mapping.
  2. Shell Injections in ngspice_ghdl.py

    • Issue: Insecure invocations of subprocess.call(..., shell=True) with unescaped string concatenations allowed command injection.
    • Resolution: Removed shell=True and migrated all process calls (compiling scripts, rmdir/rm operations) to secure shutil.rmtree and safe list-of-arguments process execution.
  3. Shell Injection in pspiceToKicad.py

    • Issue: Insecure subprocess.run(..., shell=True) execution of the parser.
    • Resolution: Replaced with safe list arguments, using sys.executable to target parser.py cleanly.

###Tests:

  • Added a full integration suite in tests/test_security_p0.py verifying all 26 edge cases, ensuring the safety of the AST expression parser. All tests are passing 100% green!

cc: @VaradhaCodes , @Eyantra698Sumanto

- plot_window.py: Replace dangerous eval() with safe AST-based math expression parser to prevent arbitrary code execution.

- pspiceToKicad.py: Remove shell=True from subprocess.run() and use list format to prevent command injection.

- tests/test_security_p0.py: Add comprehensive PoC and regression test suite proving exploitation and patch efficacy.
- Replaced dangerous shell=True subprocess calls with safe, list-based execution.

- Replaced subprocess rmdir with shutil.rmtree to safely delete model directories.

- Fixed a typo (msys_hoscme) in the Windows build path.
…standalone arm64 pyinstaller build, and beautiful DMG packager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant