Skip to content

Vulnerable Python code is not detected by CWE-094 rule #14347

Closed
@ogipierogi

Description

@ogipierogi

Description of the issue
I am trying to simulate Python code findings using an example vulnerable code:

compute = input('\nYour expression? => ')
if not compute:
    print ("No input")
else:
    print ("Result =", eval(compute))

which can be exploited e.g. using input:

__import__('os').system('ls -al /')

I also used code directly from the https://codeql.github.com/codeql-query-help/python/py-code-injection/ to check if there issue is detected by CodeQL, but it simply does not identify this code as a vulnerable for code injections.
Environment:

Python version 3.9.2
Python extractor version 5.35
CodeQL command-line toolchain release 2.14.5.

Partial logs (no other warnings or errors/failures):

Loaded /codeql/qlpacks/codeql/python-queries/0.8.4/Security/CWE-094/CodeInjection.qlx.
Starting evaluation of codeql/python-queries/Security/CWE-094/CodeInjection.ql.
[25/46 eval 19s] Evaluation done; writing results to codeql/python-queries/Security/CWE-094/CodeInjection.bqrs.

Other vulnerable code snippet which is detected by CodeQL:

from flask import app

@app.route('/')
def execute_input_noncompliant():
    from flask import request
    module_version = request.args.get("module_version")
    # Noncompliant: executes unsanitized inputs.
    exec("import urllib%s as urllib" % module_version)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions