Skip to content

Commit bedae69

Browse files
authored
RUST-1920 Use semgrep to generate SARIF reports (#1088)
1 parent b06660c commit bedae69

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

.evergreen/check-clippy.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ source ./.evergreen/env.sh
88
CLIPPY_VERSION=1.75.0
99

1010
rustup install $CLIPPY_VERSION
11-
cargo install clippy-sarif
1211

1312
# Check with default features.
1413
cargo +$CLIPPY_VERSION clippy --all-targets -p mongodb -- -D warnings
1514

1615
# Check with all features.
17-
cargo +$CLIPPY_VERSION clippy --all-targets --all-features -p mongodb -- -D warnings
18-
19-
# Produce a SARIF report.
20-
cargo +$CLIPPY_VERSION clippy --all-targets --all-features -p mongodb --message-format=json -- -D warnings | clippy-sarif > clippy.sarif.json
16+
cargo +$CLIPPY_VERSION clippy --all-targets --all-features -p mongodb -- -D warnings

.evergreen/check-semgrep.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
5+
source ./.evergreen/env.sh
6+
7+
. ${DRIVERS_TOOLS}/.evergreen/find-python3.sh
8+
PYTHON=$(find_python3)
9+
10+
if [[ -f "semgrep/bin/activate" ]]; then
11+
echo 'using existing virtualenv'
12+
. semgrep/bin/activate
13+
else
14+
echo 'Creating new virtualenv'
15+
${PYTHON} -m venv semgrep
16+
echo 'Activating new virtualenv'
17+
. semgrep/bin/activate
18+
python3 -m pip install semgrep
19+
fi
20+
21+
# Generate a SARIF report
22+
semgrep --config p/rust --sarif > mongo-rust-driver.json.sarif
23+
# And human-readable output
24+
semgrep --config p/rust --error

.evergreen/config.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ tasks:
699699
commands:
700700
- func: "check clippy"
701701

702+
- name: check-semgrep
703+
tags: [lint]
704+
commands:
705+
- func: "check semgrep"
706+
702707
- name: check-rustdoc
703708
tags: [lint]
704709
commands:
@@ -1821,6 +1826,16 @@ functions:
18211826
${PREPARE_SHELL}
18221827
.evergreen/check-clippy.sh
18231828
1829+
"check semgrep":
1830+
- command: subprocess.exec
1831+
type: test
1832+
params:
1833+
working_dir: src
1834+
add_expansions_to_env: true
1835+
binary: bash
1836+
args:
1837+
- .evergreen/check-semgrep.sh
1838+
18241839
"check rustdoc":
18251840
- command: shell.exec
18261841
type: test

.semgrepignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
benchmarks/
2+
src/test/

src/client/auth/scram.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ impl ScramVersion {
316316
) -> Result<Vec<u8>> {
317317
let normalized_password = match self {
318318
ScramVersion::Sha1 => {
319+
// nosemgrep: insecure-hashes
319320
let mut md5 = Md5::new();
320321
md5.update(format!("{}:mongo:{}", username, password));
321322
Cow::Owned(hex::encode(md5.finalize()))

src/runtime/tls_rustls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ fn make_rustls_config(cfg: TlsOptions) -> Result<rustls::ClientConfig> {
142142
};
143143

144144
if let Some(true) = cfg.allow_invalid_certificates {
145+
// nosemgrep: rustls-dangerous
145146
config
146147
.dangerous()
147148
.set_certificate_verifier(Arc::new(NoCertVerifier {}));

0 commit comments

Comments
 (0)