semgrep v0.93 releases: Fast and syntax-aware semantic code pattern search
Semgrep combines the convenient and iterative style of grep with the powerful features of an Abstract Syntax Tree (AST) matcher and limited dataflow. Easily find function calls, class or method definitions, and more without having to understand ASTs or wrestle with regexes.
Semgrep exists because:
- Insecure code is easy to write
- The future of security involves automatically guiding developers towards a “paved road” made of default-safe frameworks (i.e. React or Object-relational Mappers)
- grep isn’t expressive enough and traditional static analysis tools (SAST) are too complicated/slow for paved road automation
The AppSec, Developer, and DevOps communities deserve a static analysis tool that is fast, easy to use, code-aware, multi-lingual and open source!
Semgrep is optimized for:
- Speed: Fast enough to run on every build, commit, or file save
- Finding bugs that matter: Run your own specialized rules or choose OWASP 10 checks from the Semgrep Registry. Rules match source code at the Abstract Syntax Tree (AST) level, unlike regexes that match strings and aren’t semantically aware.
- Ease of customization: Rules look like the code you’re searching for, no static analysis Ph.D. required. They don’t require compiled code, only source, reducing iteration time.
- Ease of integration. Highly portable and many CI and git-hook integrations already exist. Output –json and pipe results into your existing systems.
- Polyglot environments: Don’t learn and maintain multiple tools for your polyglot environment (e.g. ESLint, find-sec-bugs, RuboCop, Gosec). Use the same syntax and concepts independent of language.
Pattern Syntax Teaser
One of the most unique and useful things about Semgrep is how easy it is to write and iterate on queries.
The goal is to make it as easy as possible to go from an idea in your head to find the code patterns you intend to.
Example: Say you want to find all calls to a function named exec, and you don’t care about the arguments. With Semgrep, you could simply supply the pattern exec(…) and you’d match:
Importantly, Semgrep would not match the following:
Semgrep will even match aliased imports:
Play with this example in your browser here, or copy the above code into a file locally (
exec.py) and run:
More example patterns:
- Files where only some part of the code had to be skipped due to a parse failure
will now be listed as “partially scanned” in the end-of-scan skip
- Licensing: The ocaml-tree-sitter-core component is now distributed
under the terms of the LGPL 2.1, rather than previously GPL 3.
- A new field was added to metrics collection: isAuthenticated.
This is a boolean flag which is true if you ran semgrep login.
semgrep ciused to incorrectly report the base branch as a CI job’s branch
when running on a
pull_request_targetevent in GitHub Actions.
By fixing this, Semgrep App can now track issue status history with
- Metrics events were missing timestamps even though
PRIVACY.mdhad already documented a timestamp field.
Copyright (C) 2020 returntocorp