Trail of Bits public Semgrep rules

September 3, 2025 ยท View on GitHub

This repository contains Semgrep rules developed by Trail of Bits and made available to the public. They are part of our ongoing development efforts and are used in our security audits, vulnerability reseach, and internal projects. They will evolve over time as we identify new techniques.

Visit Testing Handbook for Semgrep guidance.

Using Semgrep

The easiest way to run the rules is to run them from the Semgrep registry. To do so, navigate to the root folder of your project and run the following:

$ semgrep --config "p/trailofbits"

Alternatively, you can clone this repository, navigate to the root folder of your project, and run individual rules using the command below :

$ semgrep --config /path/to/semgrep-rules/semgreprule.yml

To run all rules from the cloned repository:

$ semgrep --config /path/to/semgrep-rules/ .

Useful flags

Semgrep will run against all supported code files except for those in your .gitignore file. If you want to run the rules against all files and directories, including those in your .gitignore, add the --no-git-ignore flag.

$ semgrep --config /path/to/semgrep-rules/ . --no-git-ignore

You can also tell Semgrep to ignore files and directories that match any pattern. For instance, if you want to tell Semgrep to ignore all Go test files you can run the following:

$ semgrep --config /path/to/semgrep-rules/ . --exclude='*_test.go'

Use -o to output results to a file:

$ semgrep --config /path/to/semgrep-rules/hanging-goroutine.yml -o leaks.txt'

Rules

go

IDPlaygroundImpactConfidenceDescription
eth-rpc-tracetransaction๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ•Detects attempts to extract trace information from an EVM transaction or block. In exchange or bridge applications, extra logic must be implemented encapsulating these endpoints to prevent the values transferred during reverted call frames from being counted.
eth-txreceipt-status๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ•Detects when a transaction receipt's status is read
hanging-goroutine๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ—Goroutine leaks
invalid-usage-of-modified-variable๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜Possible unintentional assignment when an error occurs
iterate-over-empty-map๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ—Probably redundant iteration over an empty map
missing-runlock-on-rwmutex๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Missing RUnlock on an RWMutex lock before returning from a function
missing-unlock-before-return๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Missing mutex unlock before returning from a function
nil-check-after-call๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Possible nil dereferences
racy-append-to-slice๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Concurrent calls to append from multiple goroutines
racy-write-to-map๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Concurrent writes to the same map in multiple goroutines
servercodec-readrequestbody-unhandled-nil๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜Possible incorrect ServerCodec interface implementation
string-to-int-signedness-cast๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜Integer underflows
sync-mutex-value-copied๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜Copying of sync.Mutex via value receivers
unmarshal-tag-is-dash๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
unmarshal-tag-is-omitempty๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
unsafe-dll-loading๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜Use of function vulnerable to DLL hijacking attacks
waitgroup-add-called-inside-goroutine๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Calls to sync.WaitGroup.Add inside of anonymous goroutines
waitgroup-wait-inside-loop๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Calls to sync.WaitGroup.Wait inside a loop

python

IDPlaygroundImpactConfidenceDescription
automatic-memory-pinning๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜PyTorch memory not automatically pinned
lxml-in-pandas๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜Potential XXE attacks from loading lxml in pandas
msgpack-numpy๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from functions reliant on pickling
numpy-distutils๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜Use of deprecated numpy.distutils
numpy-f2py-compile๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from NumPy f2py compilation
numpy-in-pytorch-datasets๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜Calls to the NumPy RNG inside of a Torch dataset
numpy-in-pytorch-modules๐Ÿ›๐Ÿ”—๐ŸŒซ๏ธ๐ŸŒ—Uses of NumPy functions inside PyTorch modules
numpy-load-library๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from NumPy library loading
onnx-session-options๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from ONNX library loading
pandas-eval๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ•Potential arbitrary code execution from pandas functions that evaluate user-provided expressions
pickles-in-keras-deprecation๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from Keras' load_model function
pickles-in-keras๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from Keras' load_model function
pickles-in-numpy๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from NumPy functions reliant on pickling
pickles-in-pandas๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from Pandas functions reliant on pickling
pickles-in-pytorch-distributed๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from PyTorch.Distributed functions reliant on pickling
pickles-in-pytorch๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from PyTorch functions reliant on pickling
pickles-in-tensorflow๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from tensorflow's load function
pytorch-classes-load-library๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from PyTorch library loading
pytorch-package๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ•Potential arbitrary code execution from torch.package
pytorch-tensor๐Ÿ›๐Ÿ”—๐ŸŒซ๏ธ๐ŸŒ˜Possible parsing issues and inefficiency from improper tensor creation
scikit-joblib-load๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from SciKit.Joblib functions reliant on pickling
tarfile-extractall-traversal๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ—Potential path traversal in call to extractall for a tarfile
tensorflow-load-library๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Potential arbitrary code execution from TensorFlow library loading
waiting-with-pytorch-distributed๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ—Possible PyTorch undefined behavior when not waiting for requests

rs

IDPlaygroundImpactConfidenceDescription
panic-in-function-returning-result๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜Calling unwrap or expect in a function returning a Result

javascript

IDPlaygroundImpactConfidenceDescription
schema-directives๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Use of outdated ApolloServer option 'schemaDirectives'
use-of-graphql-upload๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ•Use of the graphql-upload library
v3-potentially-bad-cors๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ•Potentially bad CORS policy
v3-express-bad-cors๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Bad CORS policy
v3-express-no-cors๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜Lack of CORS policy
v3-bad-cors๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—Bad CORS policy
v3-no-cors๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜Lack of CORS policy
v3-csrf-prevention๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜Lack of CSRF prevention
v4-csrf-prevention๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜CSRF protection disabled

ruby

IDPlaygroundImpactConfidenceDescription
action-dispatch-insecure-ssl๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
action-mailer-insecure-tls๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
active-record-encrypts-misorder๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
active-record-hardcoded-encryption-key๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
faraday-disable-verification๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
global-timeout๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
insecure-rails-cookie-session-store๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
json-create-deserialization๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ•
rails-cache-store-marshal๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ—
rails-cookie-attributes๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
rails-params-json๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ•
rest-client-disable-verification๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
ruby-saml-skip-validation๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
yaml-unsafe-load๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜

hcl

IDPlaygroundImpactConfidenceDescription
docker-hardcoded-password๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
docker-privileged-mode๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
podman-tls-verify-disabled๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
root-user๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
tls-hostname-verification-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
aws-oidc-role-policy-duplicate-condition๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
aws-oidc-role-policy-missing-sub๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
vault-hardcoded-token๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
vault-skip-tls-verify๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜

jvm

IDPlaygroundImpactConfidenceDescription
gc-call๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ˜
mongo-hostname-verification-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜

yaml

IDPlaygroundImpactConfidenceDescription
apt-key-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
apt-key-validate-certs-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
apt-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
dnf-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
dnf-validate-certs-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
get-url-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
get-url-validate-certs-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
rpm-key-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
rpm-key-validate-certs-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
unarchive-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
unarchive-validate-certs-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
wrm-cert-validation-ignore๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
yum-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
yum-validate-certs-disabled๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
zypper-repository-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
zypper-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
port-all-interfaces๐Ÿ›๐Ÿ”—๐ŸŸฉ๐ŸŒ•
aws-secret-key๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
azure-principal-secret๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
gcp-credentials-json๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
jfrog-hardcoded-credential๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
pypi-publish-password๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
rubygems-publish-key๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜
vault-token๐Ÿ›๐Ÿ”—๐ŸŸง๐ŸŒ˜

generic

IDPlaygroundImpactConfidenceDescription
amqp-unencrypted-transport๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
container-privileged๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
container-user-root๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
curl-insecure๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
curl-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
gpg-insecure-flags๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
installer-allow-untrusted๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
mongodb-insecure-transport๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
mysql-insecure-sslmode๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
node-disable-certificate-validation๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
openssl-insecure-flags๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
postgres-insecure-sslmode๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
redis-unencrypted-transport๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ˜
ssh-disable-host-key-checking๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
tar-insecure-flags๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
wget-no-check-certificate๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—
wget-unencrypted-url๐Ÿ›๐Ÿ”—๐ŸŸฅ๐ŸŒ—

swift

IDPlaygroundImpactConfidenceDescription
insecure-url-host-hassuffix-check๐Ÿ›๐Ÿ”—๐ŸŒซ๏ธ๐ŸŒ˜

Contributing

Pull Requests and issues are welcomed!

See CONTRIBUTING.md for more information.

Licensing

The rules defined in this repository are licensed under AGPLv3.

The sidecar examples may be derived from other works, and retain their original licenses where required.