AGENDA
• History
• What is Semgrep?
• SAST Tools Slider
• Rule Syntax
• Writing Rules | Demo
• Usage
• Limitations
• QnA
HISTORY: SGREP (SYNTACTIC GREP)
• Initially called Sgrep/Pfff
• Written By Yoann Padioleau at Facebook for analyzing PHP code
• Was used to Enforce Best Practices
• Easy for developers to organize and understand the rules
• Joined R2C and renamed Sgrep to Semgrep
• Goal was to match based on semantics of the code
Reference: https://semgrep.dev/blog/2021/semgrep-a-static-analysis-journey
WHAT IS SEMGREP?
• Fast and lightweight static analysis tool to find bugs and enforce code
standards.
Reference: https://semgrep.dev/
PROS
• Opensource
• Rules look like the code you already write; no abstract syntax trees, regex
wrestling
• Scans in minutes
• Does not require a build
• Hunt Bugs at scale
• Supports many languages
• Very easy to write custom rules
DEEP EXPRESSION
• Deep Expression Operator: “<… [your pattern]…>”
• Scenario: XML Parser allows resolving external resources
• Solution:
https://semgrep.dev/orgs/nikhil1232/editor/s/nikhil1232:owasp-
xmltextreader
• Reference: https://rules.sonarsource.com/csharp/RSPEC-2755,
https://pvs-studio.com/en/blog/posts/csharp/0918/
METAVARIABLE REGEX
• Scenario: App not validating the expiration time of a JWT
• Solution:
https://semgrep.dev/orgs/nikhil1232/editor/s/nikhil1232:owasp-jwt-no-
expiry
• Reference: https://github.com/returntocorp/semgrep-
rules/blob/develop/csharp/lang/security/ad/jwt-
tokenvalidationparameters-no-expiry-validation.cs