2021-11-09 15:01:30 +01:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
|
|
|
|
Arguments like `-delete` or `-exec` for the `find` command can alter the expected behavior and result in vulnerabilities:
|
|
|
|
----
|
|
|
|
import subprocess
|
|
|
|
input = request.get('input')
|
|
|
|
subprocess.run(["/usr/bin/find", input]) # Sensitive
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
Use an allow-list to restrict the arguments to trusted values:
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,python]
|
2021-11-09 15:01:30 +01:00
|
|
|
----
|
|
|
|
import subprocess
|
|
|
|
input = request.get('input')
|
|
|
|
if input in allowed:
|
|
|
|
subprocess.run(["/usr/bin/find", input])
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
endif::env-github,rspecator-view[]
|