How do you write a simple Semgrep rule?
IntermediateConceptApplication Security Testing (SAST, DAST, SCA, Secrets)
Answer
rules:
- id: python-subprocess-shell-true
languages: [python]
severity: ERROR
message: subprocess called with shell=True; pass an argument list instead
pattern: subprocess.$FUNC(..., shell=True, ...)
Run it with semgrep --config rules.yml . or use registry packs like semgrep --config p/owasp-top-ten. $FUNC is a metavariable and ... matches any arguments.
More on Application Security Testing (SAST, DAST, SCA, Secrets)
What is SAST and what are its strengths and limits?BeginnerWhat is DAST and how does it differ from SAST?BeginnerWhat is IAST and RASP?IntermediateWhat is SCA and what does it scan?BeginnerHow does a SAST tool find a SQL injection using taint analysis?AdvancedWhat is CodeQL and how does its model differ from Semgrep?Intermediate