Skip to content
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

Merge Develop into Release #3237

Merged
merged 24 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
18323ee
Fix jsonwebtoken rule for fps (#3219)
LewisArdern Nov 15, 2023
7de1c21
Merge Gitleaks rules 2023-11-15 # 22:25
Nov 15, 2023
7a90452
update test case
LewisArdern Nov 15, 2023
75ae126
Fix test case
LewisArdern Nov 15, 2023
47e42f9
Merge pull request #3222 from semgrep/merge-gitleaks-to-develop
LewisArdern Nov 15, 2023
8ab710b
Merge Gitleaks rules 2023-11-16 # 01:30
Nov 16, 2023
5dba08f
Merge pull request #3224 from semgrep/merge-gitleaks-to-develop
LewisArdern Nov 16, 2023
95a2129
Add rules helpful for auditing ocaml code bases (#3092)
EricSesterhennX41 Nov 17, 2023
1bf05c1
Merge Gitleaks rules 2023-11-20 # 01:30 (#3227)
r2c-argo[bot] Nov 20, 2023
d3bed5f
Add rule_type to update registry calls (#3226)
jarrydlee Nov 20, 2023
ebd6b96
Bump aiohttp from 3.8.5 to 3.8.6 in /.github/rulerascal (#3228)
dependabot[bot] Nov 21, 2023
06d5e99
Add refs to ocaml security rules (#3229)
inkz Nov 21, 2023
aa0afb5
Add additional sink for XSS and HTML injection in php (#3217)
appills Nov 21, 2023
54e7d73
Skip elixir which is now in Pro (#3230)
aryx Nov 21, 2023
caf9742
Update detected-aws-access-key-id-value.yaml with boundary
LewisArdern Nov 28, 2023
224ee32
Merge pull request #3235 from semgrep/LewisArdern-patch-1
LewisArdern Nov 29, 2023
042f310
update django-no-csrf-token rule (#3231)
inkz Nov 30, 2023
cf8c8b5
Fix autofixes
LewisArdern Dec 7, 2023
e2b04a5
improve autofixes
LewisArdern Dec 7, 2023
6792dba
fix references
LewisArdern Dec 7, 2023
0053f36
fix reference
LewisArdern Dec 7, 2023
c3e2c62
fix
LewisArdern Dec 7, 2023
a8a8e00
fix
LewisArdern Dec 7, 2023
3ce808c
Merge pull request #3239 from semgrep/fixerino
LewisArdern Dec 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .codemapignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- sh -*-
# gitignore-like file for Codemap (see https://github.com/aryx/codemap)
# The goal here is to just show and count the rules in codemap

# skipping all files, targets and rules (but rules will be restored below)
[a-z]*/**/*.*

# restore directories which are not languages
# coupling: see scripts/run-test rule_folders variable
!libsonnet/
!scripts/
!stats/
# restore also fingerprints/ ? trusted_python/ ?

# do not skip the rules
![a-z]*/**/*.yaml

# pad stuff
/TODO/
178 changes: 89 additions & 89 deletions .github/rulerascal/poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/update-semgrep-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:

jobs:
do-update:
if: github.repository == 'returntocorp/semgrep-rules'
if: github.repository == 'semgrep/semgrep-rules'
name: Update semgrep.dev
runs-on: ubuntu-latest
steps:
- name: update semgrep.dev
run: curl --fail -X POST -L https://semgrep.dev/api/admin/update-registry
run: curl --fail -X POST -L https://semgrep.dev/api/admin/update-registry?rule_type=sast
6 changes: 3 additions & 3 deletions .github/workflows/update-semgrep-staging-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:

jobs:
do-update:
if: github.repository == 'returntocorp/semgrep-rules'
if: github.repository == 'semgrep/semgrep-rules'
name: Update semgrep.dev
runs-on: ubuntu-latest
steps:
- name: update dev.semgrep.dev
run: curl --fail -X POST -L https://dev.semgrep.dev/api/admin/update-registry
run: curl --fail -X POST -L https://dev.semgrep.dev/api/admin/update-registry?rule_type=sast
continue-on-error: true
- name: update staging.semgrep.dev
run: curl --fail -X POST -L https://staging.semgrep.dev/api/admin/update-registry
run: curl --fail -X POST -L https://staging.semgrep.dev/api/admin/update-registry?rule_type=sast
2 changes: 1 addition & 1 deletion generic/secrets/gitleaks/aws-access-token.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ rules:
technology:
- gitleaks
patterns:
- pattern-regex: (A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}
- pattern-regex: (?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}
2 changes: 2 additions & 0 deletions generic/secrets/gitleaks/hashicorp-tf-password.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// ruleid: hashicorp-tf-password
administrator_login_password = "thisIsDog11"
26 changes: 26 additions & 0 deletions generic/secrets/gitleaks/hashicorp-tf-password.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
rules:
- id: hashicorp-tf-password
message: A gitleaks hashicorp-tf-password was detected which attempts to identify hard-coded credentials. It is not recommended to store credentials in source-code, as this risks secrets being leaked and used by either an internal or external malicious adversary. It is recommended to use environment variables to securely provide credentials or retrieve credentials from a secure vault or HSM (Hardware Security Module).
languages:
- regex
severity: INFO
metadata:
likelihood: LOW
impact: MEDIUM
confidence: LOW
category: security
cwe:
- "CWE-798: Use of Hard-coded Credentials"
cwe2021-top25: true
cwe2022-top25: true
owasp:
- A07:2021 - Identification and Authentication Failures
references:
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
source-rule-url: https://github.com/zricethezav/gitleaks/tree/master/cmd/generate/config/rules
subcategory:
- vuln
technology:
- gitleaks
patterns:
- pattern-regex: (?i)(?:administrator_login_password|password)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}("[a-z0-9=_\-]{8,20}")(?:['|\"|\n|\r|\s|\x60|;]|$)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rules:
- id: detected-aws-access-key-id-value
patterns:
- pattern-regex: (A3T[A-Z0-9]|AKIA|AGPA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}
- pattern-regex: \b(A3T[A-Z0-9]|AKIA|AGPA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}\b
- pattern-not-regex: (?i)example|sample|test|fake
languages: [regex]
message: AWS Access Key ID Value detected. This is a sensitive credential and should not be hardcoded
Expand Down
6 changes: 0 additions & 6 deletions java/servlets/security/cookie-issecure-false.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ public void bad1() {
// ruleid: cookie-issecure-false
Cookie cookie = new Cookie("name", "value");
}

public void bad2() {
// ruleid: cookie-issecure-false
Cookie cookie = new Cookie("name", "value");
cookie.setSecure(false);
}
}

public class Ok {
Expand Down
70 changes: 35 additions & 35 deletions java/servlets/security/cookie-issecure-false.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
rules:
- id: cookie-issecure-false
patterns:
- pattern: |
$COOKIE = new Cookie(...);
- pattern-not-inside: |
$COOKIE = new Cookie(...);
...
$COOKIE.setSecure(true);
message: >-
Default session middleware settings: `setSecure` not set to true.
This ensures that the cookie is sent only over HTTPS to prevent cross-site scripting attacks.
fix-regex:
regex: setSecure\(false\)
replacement: setSecure(true)
metadata:
vulnerability: Insecure Transport
owasp:
- A03:2017 - Sensitive Data Exposure
- A02:2021 - Cryptographic Failures
cwe:
- 'CWE-319: Cleartext Transmission of Sensitive Information'
references:
- https://tomcat.apache.org/tomcat-5.5-doc/servletapi/
category: security
technology:
- servlet
- tomcat
subcategory:
- audit
likelihood: LOW
impact: LOW
confidence: LOW
languages:
- java
severity: WARNING
- id: cookie-issecure-false
patterns:
- pattern: $COOKIE = new Cookie($...ARGS);
- pattern-not-inside: |
$COOKIE = new Cookie(...);
...
$COOKIE.setSecure(...);
message: "Default session middleware settings: `setSecure` not set to true. This
ensures that the cookie is sent only over HTTPS to prevent cross-site
scripting attacks."
fix: |
$COOKIE = new Cookie($...ARGS);
$COOKIE.setSecure(true);
metadata:
vulnerability: Insecure Transport
owasp:
- A03:2017 - Sensitive Data Exposure
- A02:2021 - Cryptographic Failures
cwe:
- "CWE-319: Cleartext Transmission of Sensitive Information"
references:
- https://docs.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html#setSecure(boolean)
- https://owasp.org/www-community/controls/SecureCookieAttribute
category: security
technology:
- java
- cookie
subcategory:
- audit
likelihood: LOW
impact: LOW
confidence: LOW
languages:
- java
severity: WARNING
16 changes: 16 additions & 0 deletions java/servlets/security/cookie-setSecure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Bad {

public void bad2() {
Cookie cookie = new Cookie("name", "value");
// ruleid: cookie-setSecure
cookie.setSecure(false);
}
}

public class Ok {
public void ok1() {
// ok: cookie-setSecure
Cookie cookie = new Cookie("name", "value");
cookie.setSecure(true);
}
}
41 changes: 41 additions & 0 deletions java/servlets/security/cookie-setSecure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
rules:
- id: cookie-setSecure
patterns:
- patterns:
- pattern-inside: |
$COOKIE = new Cookie(...);
...
- pattern: |
$COOKIE.setSecure(false);
- pattern-not-inside: |
$COOKIE = new Cookie(...);
...
$COOKIE.setSecure(true);
message: "Default session middleware settings: `setSecure` not set to true. This
ensures that the cookie is sent only over HTTPS to prevent cross-site
scripting attacks."
fix-regex:
regex: setSecure\(false\)
replacement: setSecure(true)
metadata:
vulnerability: Insecure Transport
owasp:
- A03:2017 - Sensitive Data Exposure
- A02:2021 - Cryptographic Failures
cwe:
- "CWE-319: Cleartext Transmission of Sensitive Information"
references:
- https://docs.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html#setSecure(boolean)
- https://owasp.org/www-community/controls/SecureCookieAttribute
category: security
technology:
- java
- cookie
subcategory:
- audit
likelihood: LOW
impact: LOW
confidence: LOW
languages:
- java
severity: WARNING
29 changes: 9 additions & 20 deletions javascript/jsonwebtoken/security/jwt-hardcode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@ rules:
severity: WARNING
mode: taint
pattern-sources:
- patterns:
- pattern-either:
- patterns:
- patterns:
- pattern: |
$X = '...'
- pattern: |
$X = '$Y'
- patterns:
- pattern-either:
- pattern-inside: |
$VALUE = '$Y'
...
- pattern: $VALUE
- patterns:
- pattern-either:
- pattern-inside: $JWT.sign($VALUE, $Y,...)
- pattern-inside: $JWT.verify($VALUE, $Y,...)
- focus-metavariable: $Y
- pattern: >
'...'
- patterns:
$JWT.sign($DATA,"...",...);
- pattern-inside: |
$SECRET = "$Y"
...
class $FUNC {
...
}
- pattern: $SECRET
$JWT.verify($DATA,"...",...);
pattern-sinks:
- patterns:
- pattern-either:
Expand Down
3 changes: 3 additions & 0 deletions ocaml/lang/security/digest.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(* ruleid:ocamllint-digest *)
let a = Digest.string "asd" in
Printf.printf "%s\n" a
25 changes: 25 additions & 0 deletions ocaml/lang/security/digest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rules:
- id: ocamllint-digest
pattern-either:
- pattern: Digest.string
- pattern: Digest.bytes
- pattern: Digest.substring
- pattern: Digest.subbytes
- pattern: Digest.channel
- pattern: Digest.file
message: Digest uses MD5 and should not be used for security purposes. Consider using SHA256 instead.
languages: [ocaml]
severity: WARNING
metadata:
category: security
references:
- https://v2.ocaml.org/api/Digest.html
technology:
- ocaml
cwe: "CWE-328: Use of Weak Hash (4.12)"
confidence: LOW
likelihood: MEDIUM
impact: MEDIUM
subcategory:
- audit

12 changes: 12 additions & 0 deletions ocaml/lang/security/exec.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#load "unix.cma";;
let p = String.concat "ls " [" "; Sys.argv.(1)]
(* ruleid:ocamllint-exec *)
let a = Unix.execve p
(* ruleid:ocamllint-exec *)
let b = Unix.execvp p
(* ruleid:ocamllint-exec *)
let c = Unix.execvpe p
(* ruleid:ocamllint-exec *)
let d = Unix.system p
(* ruleid:ocamllint-exec *)
let e = Sys.command p
29 changes: 29 additions & 0 deletions ocaml/lang/security/exec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
rules:
- id: ocamllint-exec
patterns:
- pattern-either:
- pattern: Unix.execve $STR
- pattern: Unix.execvp $STR
- pattern: Unix.execvpe $STR
- pattern: Unix.system $STR
- pattern: Sys.command $STR
- pattern-not: Unix.execve "..."
- pattern-not: Unix.execvp "..."
- pattern-not: Unix.execvpe "..."
- pattern-not: Unix.system "..."
- pattern-not: Sys.command "..."
message: Executing external programs might lead to comand or argument injection vulnerabilities.
languages: [ocaml]
severity: WARNING
metadata:
category: security
references:
- https://v2.ocaml.org/api/Unix.html
technology:
- ocaml
cwe: "CWE-78: OS Command Injection"
confidence: LOW
likelihood: MEDIUM
impact: HIGH
subcategory:
- audit
3 changes: 3 additions & 0 deletions ocaml/lang/security/filenameconcat.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(* ruleid:ocamllint-filenameconcat *)
let ofile = Filename.concat "test" "../data" in
Printf.printf "%s\n" ofile
18 changes: 18 additions & 0 deletions ocaml/lang/security/filenameconcat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rules:
- id: ocamllint-filenameconcat
pattern: Filename.concat
message: When attacker supplied data is passed to Filename.concat directory traversal attacks might be possible.
languages: [ocaml]
severity: WARNING
metadata:
category: security
references:
- https://v2.ocaml.org/api/Filename.html
technology:
- ocaml
cwe: "CWE-35: Path Traversal"
confidence: LOW
likelihood: MEDIUM
impact: MEDIUM
subcategory:
- audit
8 changes: 8 additions & 0 deletions ocaml/lang/security/hashtable-dos.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(* ruleid:ocamllint-hashtable-dos *)
let h = Hashtbl.create 16 in
for i = 1 to 1000 do Hashtbl.add h i (i * 2) done;
Printf.printf "%i elements\n" (Hashtbl.length h);

let j = Hashtbl.create 16 ~random:true in
for i = 1 to 1000 do Hashtbl.add j i (i * 2) done;
Printf.printf "%i elements\n" (Hashtbl.length j);
Loading
Loading