Generic SAST for Security Engineers. Powered by tree-sitter AST pattern matcher, regex based pattern matcher, and semantic aware semgrep.
Made with in India
Support libsast
Donate via Paypal:
Sponsor the Project:
Install
pip install libsast
# Optional Tree-sitter language grammar extras:
pip install "libsast[treesitter]" # 165+ languages via tree-sitter-language-pack
pip install "libsast[mobile]" # JS, TS/TSX, Java, Kotlin, Swift, ObjC, C#
pip install "libsast[js]" # JavaScript and TypeScript/TSX
# Or install any individual tree-sitter-<lang> package alongside libsast:
pip install libsast tree-sitter-python
# Optional Semgrep support (macOS/Linux):
pip install semgrep==1.172.0
Pattern Matcher and Tree-sitter Matcher are cross-platform (Windows, macOS, and Linux). Semgrep supports macOS and Linux.
Command Line Options
$ libsast
usage: libsast [-h] [-o OUTPUT] [-p PATTERN_FILE] [-t TS_PATTERN_FILE]
[-s SGREP_PATTERN_FILE]
[--ts-file-extensions TS_FILE_EXTENSIONS [TS_FILE_EXTENSIONS ...]]
[--sgrep-file-extensions SGREP_FILE_EXTENSIONS [SGREP_FILE_EXTENSIONS ...]]
[--file-extensions FILE_EXTENSIONS [FILE_EXTENSIONS ...]]
[--ignore-filenames IGNORE_FILENAMES [IGNORE_FILENAMES ...]]
[--ignore-extensions IGNORE_EXTENSIONS [IGNORE_EXTENSIONS ...]]
[--ignore-paths IGNORE_PATHS [IGNORE_PATHS ...]]
[--show-progress] [--cpu-core CPU_CORE] [-v]
[path ...]
positional arguments:
path Path can be file(s) or directories
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output filename to save JSON report.
-p PATTERN_FILE, --pattern-file PATTERN_FILE
YAML pattern file, directory or url
-t TS_PATTERN_FILE, --ts-pattern-file TS_PATTERN_FILE
Tree-sitter YAML pattern file, directory or url
-s SGREP_PATTERN_FILE, --sgrep-pattern-file SGREP_PATTERN_FILE
sgrep rules directory
--ts-file-extensions TS_FILE_EXTENSIONS [TS_FILE_EXTENSIONS ...]
File extensions that should be scanned with
tree-sitter matcher
--sgrep-file-extensions SGREP_FILE_EXTENSIONS [SGREP_FILE_EXTENSIONS ...]
File extensions that should be scanned with semantic
grep
--file-extensions FILE_EXTENSIONS [FILE_EXTENSIONS ...]
File extensions that should be scanned with pattern
matcher
--ignore-filenames IGNORE_FILENAMES [IGNORE_FILENAMES ...]
File name(s) to ignore
--ignore-extensions IGNORE_EXTENSIONS [IGNORE_EXTENSIONS ...]
File extension(s) to ignore in lower case
--ignore-paths IGNORE_PATHS [IGNORE_PATHS ...]
Path(s) to ignore
--show-progress Show scan progress
--cpu-core CPU_CORE No of CPU cores to use. Use all cores by default
-v, --version Show libsast version
With libsast, you can write your own static analysis tools. libsast provides three matching engines:
Pattern Matcher (Regex)
Tree-sitter Matcher (AST)
Semantic Grep (Semgrep)
Pattern Matcher
Pattern Matcher supports any language.
Use Regex 101 to write simple Python Regex rule patterns.
A sample rule looks like
- id: test_regex_or
message: This is a rule to test regex_or
input_case: exact
pattern:
- MODE_WORLD_READABLE|Context\.MODE_WORLD_READABLE
- openFileOutput\(\s*".+"\s*,\s*1\s*\)
severity: error
type: RegexOr
metadata:
owasp-web: a1
reference: http://foo.bar
foo: Some extra metadata
A rule consists of
id : A unique id for the rule.
message: A description for the rule.
input_case: It can be exact, upper or lower. Data will be converted to lower case/upper case/as it is before comparing with the regex.
pattern: List of patterns depends on type.
severity: It can be error, warning or info.
type: Pattern Matcher supports Regex, RegexAnd, RegexOr, RegexAndOr, RegexAndNot (as well as TreeSitter, TreeSitterAnd, TreeSitterOr, TreeSitterAndOr, TreeSitterAndNot).
metadata (optional): Define your own custom fields that you can use as metadata along with standard mappings.
1. Regex - if regex1 in input
2. RegexAnd - if regex1 in input and regex2 in input
3. RegexOr - if regex1 in input or regex2 in input
4. RegexAndOr - if regex1 in input and (regex2 in input or regex3 in input)
5. RegexAndNot - if regex1 in input and not regex2 in input
pattern: Tree-sitter S-expression query (or list of queries) capturing @match.
languages (optional): List of Tree-sitter language names the rule applies to.
exclude_ancestor (optional): S-expression query; suppresses matches nested inside a matching ancestor node (e.g., if (__DEV__)).
within_ancestor (optional): S-expression query; requires @match to be nested inside a matching ancestor node.
not_within_node (optional): S-expression query; suppresses @match if the matched node itself contains a sub-node matching this query (e.g., missing-property checks).