forked from boost-community/scanner-registry
-
Notifications
You must be signed in to change notification settings - Fork 1
Semgrep - Improve pre scan checks and ease of extending rules #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7a69586
Add CWE-1427 - Prompt Injection (#227) (#193)
fproulx-boostsecurity ed6025b
Merge remote-tracking branch 'community/main' into semgrep/default
Franck-Boost e6132ec
Improve semgrep prescan checks and ease semgrep rules extension
Franck-Boost 32e3f23
Stripping querystring and hash tag from URL
Franck-Boost 9ce16bb
Force overwrite
Franck-Boost 492d3de
Improved local configurations checks
Franck-Boost 8ebbb02
Existing on no yaml file
Franck-Boost 1296dc2
Update scanners/boostsecurityio/semgrep/prescan_checks.sh
Franck-Boost b401909
Exiting on inexisting local rule
Franck-Boost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/bin/bash | ||
| local_rules_dst=$(mktemp -d) | ||
| if [ -d ".semgrep" ] | ||
| then | ||
| mv .semgrep/ "$local_rules_dst" | ||
| fi | ||
| mkdir -p .semgrep | ||
|
|
||
| fetch_remote() { | ||
| file_name="${1##*/}" | ||
| file_name=$(echo $file_name | cut -d '#' -f 1 | cut -d '?' -f 1) | ||
| file_extension="${file_name##*.}" | ||
| if [ "$file_extension" != "yaml" ] && [ "$file_extension" != "yml" ] | ||
| then | ||
| >&2 echo "Semgrep custom rules validation failed." | ||
| >&2 echo " The provided URL does not point to a YAML file: $1." | ||
| rm -rf $local_rules_dst | ||
| exit 1 | ||
| fi | ||
|
|
||
| dst_file=$(mktemp --suffix=.yml) | ||
| http_code=$(curl -s -L --fail -w '%{http_code}\n' -o $dst_file $1) | ||
| if [ "${http_code}" == "200" ] | ||
| then | ||
| cp $dst_file .semgrep/ | ||
| rm -f $dst_file | ||
| return 0 | ||
| fi | ||
|
|
||
| >&2 echo "Semgrep custom rules - Cannot fetch $1." | ||
| rm -f $dst_file | ||
| rm -rf $local_rules_dst | ||
| exit 1 | ||
| } | ||
|
|
||
| SEMGREP_RULES=${SEMGREP_RULES:-boost/sast/rules/semgrep@stable} | ||
| for rule in $SEMGREP_RULES; do | ||
| case "$rule" in | ||
| .semgrep/*) | ||
| # Local rules are allowed | ||
| if [ "$rule" == ".semgrep/*" ] | ||
| then | ||
| # | ||
| cp -R -f $local_rules_dst/.semgrep/* .semgrep || true | ||
| else | ||
| if [ ! -f "$local_rules_dst/$rule" ] && [ ! -d "$local_rules_dst/$rule" ] | ||
| then | ||
| >&2 echo "Semgrep custom rules validation failed." | ||
| >&2 echo " The specific file or directory does not exist in the code repository: $rule." | ||
| exit 1 | ||
| fi | ||
| cp -R -f "$local_rules_dst/$rule" .semgrep || true | ||
| fi | ||
| ;; | ||
| http://*|https://*) | ||
| fetch_remote $rule | ||
| ;; | ||
| boost/sast/rules/semgrep@*) | ||
| # Boost | ||
| version=$(echo "$rule" | cut -d '@' -f 2) | ||
| # $version is not sanitized since one can provide any URL in the boost config | ||
| fetch_remote "https://assets.build.boostsecurity.io/semgrep-rules/$version/all-sast-rules.yml" | ||
| ;; | ||
| *) | ||
| >&2 echo "Semgrep custom rules validation failed on $rule." | ||
| >&2 echo " Community rules cannot be used." | ||
| >&2 echo " Provide a URL or relative path to rules file or leave blank for Boost curated rules." | ||
| rm -rf $local_rules_dst | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| rm -rf $local_rules_dst | ||
|
|
||
| if [ "$(find .semgrep -regex '.*\.ya?ml' | wc -l)" == "0" ] | ||
| then | ||
| >&2 echo "Semgrep custom rules validation failed for $SEMGREP_RULES." | ||
| >&2 echo " Missing yaml configuration files" | ||
| exit 1 | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.