Skip to content

Issues with testing env(input) and Pythonic SQLi [CodeShield] #91

@njmennona

Description

@njmennona

Hello:
I am learning how to best use CodeShield. I have been trying to use CodeShield to detect SQLi (SQL Injections). I haven't been able to get CodeShield to use its rules to detect any Pythonic SQLi To clarify my issues, after writing my own SQLi, I inserted examples from the code blocks found in: CodeShield/insecure_code_detector/rules/semgrep/python/sql_injection_cursor_execute.py into the str llm_output_code found in CodeShield/notebook/CodeShieldUsageDemo.ipynb in place of the md5 insecurity (Example 1 - Simple hard-coded example). I want to emphasize, however, that running semgrep in the command line (using --config sql_injection_cursor_execute.yaml) for that .py file correctly identifies all of the SQLi.

After these difficulties with SQLi, I ran the testing file found in: CodeShield/tests/test_codeshield.py. When I ran this, the output of scan_code for the input: ("eval(input)", True) evaluates to False for scan_results.is_insecure, i.e. scan_results = await CodeShield.scan_code(test_input)->False for test_input := "eval(input)". When I modified test_codeshield.py to include the original Example 1 md5 insecurity: """def hashString(input):
return hashlib.md5(input)""", scan_code produced the correct output (scan_results = True).

In summary, I cannot get CodeShield to identify vulnerabilities outside of the narrow example case provided in the Usage Demo (md5 error). I have used both CodeShieldUsageDemo.ipynb and test_codeshield.py to arrive at this conclusion; I have used examples that are included in CodeShield's documentation.

Please let me know if there is something I am misunderstanding or doing incorrectly. I appreciate any time devoted to this issue, and your patience in taking the time to understand my difficulties. Please let me know if any part of my explanation is unclear. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions