-
Notifications
You must be signed in to change notification settings - Fork 9
Add TypeScript security rules and tooling #198
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,3 +197,4 @@ cscope.in.out | |
cscope.po.out | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/node,tags,macos | ||
.claude |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
"devDependencies": { | ||
"@ast-grep/cli": "^0.31.1" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,4 +259,4 @@ rule: | |
- inside: | ||
stopBy: end | ||
kind: return_statement | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,4 +259,4 @@ rule: | |
- inside: | ||
stopBy: end | ||
kind: return_statement | ||
|
||
|
||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,4 @@ rule: | |
kind: ERROR | ||
- has: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -77,4 +77,4 @@ rule: | |||
stopBy: end | ||||
kind: attribute_value | ||||
regex: ^([Hh][Tt][Tt][Pp]://) | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strip trailing whitespace to satisfy YAML linting YAML-lint reports a -
+ 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 80-80: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,4 +126,4 @@ rule: | |
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,4 +317,4 @@ constraints: | |
all: | ||
- has: | ||
kind: string_fragment | ||
regex: ^\s*(AES)\s*$ | ||
regex: ^\s*(AES)\s*$ |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -106,4 +106,4 @@ constraints: | |||
has: | ||||
kind: string_fragment | ||||
regex: ^MD5 | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing whitespace to satisfy YAML linting Line 109 is an otherwise blank line containing stray spaces, triggering -
+ 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 109-109: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,4 +169,4 @@ rule: | |
- not: | ||
has: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -648,4 +648,4 @@ rule: | |
- not: | ||
inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,4 @@ rule: | |
- not: | ||
inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -72,4 +72,4 @@ rule: | |||
stopBy: end | ||||
kind: ERROR | ||||
|
||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing whitespace to pass YAML lint
-
+ 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 75-75: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,4 @@ rule: | |
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,4 +66,4 @@ rule: | |
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,4 @@ rule: | |
- not: | ||
inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,4 @@ rule: | |
- not: | ||
inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,4 +129,4 @@ rule: | |
|
||
constraints: | ||
PASS: | ||
kind: string | ||
kind: string |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,4 +156,4 @@ rule: | |
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR | ||
kind: ERROR |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -196,4 +196,4 @@ rule: | |||
- inside: | ||||
stopBy: end | ||||
kind: ERROR | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing whitespace to satisfy YAML linting
-
+ 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 199-199: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
id: argon2-weak-type-typescript | ||
severity: error | ||
language: typescript | ||
message: >- | ||
Use secure encryption types when using `argon2`. Avoid using weak argon2 types | ||
like argon2i or argon2d. Use argon2id instead for better security. | ||
note: >- | ||
[CWE-327] Use of a Broken or Risky Cryptographic Algorithm. | ||
[REFERENCES] | ||
- https://github.com/ranisalt/node-argon2/wiki/Options#type | ||
ast-grep-essentials: true | ||
utils: | ||
MATCH_ARGON2_WEAK_TYPE: | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: member_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: "^argon2$" | ||
- has: | ||
stopBy: neighbor | ||
kind: property_identifier | ||
regex: "^hash$" | ||
- has: | ||
stopBy: neighbor | ||
kind: arguments | ||
has: | ||
stopBy: neighbor | ||
kind: object | ||
has: | ||
stopBy: neighbor | ||
kind: pair | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: property_identifier | ||
regex: "^type$" | ||
- has: | ||
stopBy: neighbor | ||
kind: member_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: "^argon2$" | ||
- has: | ||
stopBy: neighbor | ||
kind: property_identifier | ||
any: | ||
- regex: "^argon2i$" | ||
- regex: "^argon2d$" | ||
rule: | ||
kind: call_expression | ||
any: | ||
- matches: MATCH_ARGON2_WEAK_TYPE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
id: avoid-crypto-rc4-typescript | ||
severity: warning | ||
language: typescript | ||
message: >- | ||
Avoid RC4 encryption. Use of the RC4 security protocol exposes your | ||
application to vulnerabilities. Consider using stronger encryption algorithms. | ||
note: >- | ||
[CWE-328] Use of Weak Hash. | ||
[REFERENCES] | ||
- https://cryptojs.gitbook.io/docs/#ciphers | ||
ast-grep-essentials: true | ||
utils: | ||
MATCH_RC4_USAGE: | ||
kind: call_expression | ||
has: | ||
stopBy: neighbor | ||
kind: member_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: member_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: "^CryptoJS$" | ||
- has: | ||
stopBy: neighbor | ||
kind: property_identifier | ||
any: | ||
- regex: "^RC4$" | ||
- regex: "^RC4Drop$" | ||
- has: | ||
stopBy: neighbor | ||
kind: property_identifier | ||
any: | ||
- regex: "^encrypt$" | ||
- regex: "^decrypt$" | ||
rule: | ||
kind: call_expression | ||
any: | ||
- matches: MATCH_RC4_USAGE |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||
id: avoid-crypto-sha1-typescript | ||||||||||||||||||||||||||
severity: warning | ||||||||||||||||||||||||||
language: typescript | ||||||||||||||||||||||||||
message: >- | ||||||||||||||||||||||||||
Avoid SHA1 security protocol. Use of insecure encryption or hashing protocols | ||||||||||||||||||||||||||
expose your application to vulnerabilities. Use stronger hashing algorithms like SHA-256. | ||||||||||||||||||||||||||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing spaces to unblock YAML-lint. The current message block fails - Avoid SHA1 security protocol. Use of insecure encryption or hashing protocols␠
+ Avoid SHA1 security protocol. Use of insecure encryption or hashing protocols 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 5-5: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||
note: >- | ||||||||||||||||||||||||||
[CWE-328] Use of Weak Hash. | ||||||||||||||||||||||||||
[REFERENCES] | ||||||||||||||||||||||||||
- https://cryptojs.gitbook.io/docs/#hmac | ||||||||||||||||||||||||||
ast-grep-essentials: true | ||||||||||||||||||||||||||
utils: | ||||||||||||||||||||||||||
MATCH_SHA1_USAGE: | ||||||||||||||||||||||||||
kind: call_expression | ||||||||||||||||||||||||||
all: | ||||||||||||||||||||||||||
- has: | ||||||||||||||||||||||||||
stopBy: neighbor | ||||||||||||||||||||||||||
kind: member_expression | ||||||||||||||||||||||||||
all: | ||||||||||||||||||||||||||
- has: | ||||||||||||||||||||||||||
stopBy: neighbor | ||||||||||||||||||||||||||
kind: identifier | ||||||||||||||||||||||||||
regex: "^CryptoJS$" | ||||||||||||||||||||||||||
- has: | ||||||||||||||||||||||||||
stopBy: neighbor | ||||||||||||||||||||||||||
kind: property_identifier | ||||||||||||||||||||||||||
regex: "^HmacSHA1$" | ||||||||||||||||||||||||||
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Broaden the pattern to catch Only - regex: "^HmacSHA1$"
+ any:
+ - regex: "^HmacSHA1$"
+ - regex: "^SHA1$" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||
- has: | ||||||||||||||||||||||||||
stopBy: neighbor | ||||||||||||||||||||||||||
kind: arguments | ||||||||||||||||||||||||||
rule: | ||||||||||||||||||||||||||
kind: call_expression | ||||||||||||||||||||||||||
any: | ||||||||||||||||||||||||||
- matches: MATCH_SHA1_USAGE |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||||||
id: avoid-des-typescript | ||||||||||
severity: warning | ||||||||||
language: typescript | ||||||||||
message: >- | ||||||||||
Do not use DES or TripleDES, this is a weak security protocol. Use stronger | ||||||||||
encryption algorithms like AES instead. | ||||||||||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trim trailing spaces to satisfy linters. - Do not use DES or TripleDES, this is a weak security protocol. Use stronger ␠
+ Do not use DES or TripleDES, this is a weak security protocol. Use stronger 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 5-5: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
|
||||||||||
note: >- | ||||||||||
[CWE-328] Use of Weak Hash. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Incorrect CWE reference – use CWE-327 (Broken or Risky Crypto Algorithm). DES weaknesses are covered by CWE-327, not CWE-328 (weak hash). Update for accuracy. - [CWE-328] Use of Weak Hash.
+ [CWE-327] Use of a Broken or Risky Cryptographic Algorithm. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||
[REFERENCES] | ||||||||||
- https://cryptojs.gitbook.io/docs/#ciphers | ||||||||||
ast-grep-essentials: true | ||||||||||
utils: | ||||||||||
MATCH_DES_USAGE: | ||||||||||
kind: call_expression | ||||||||||
has: | ||||||||||
stopBy: neighbor | ||||||||||
kind: member_expression | ||||||||||
all: | ||||||||||
- has: | ||||||||||
stopBy: neighbor | ||||||||||
kind: member_expression | ||||||||||
all: | ||||||||||
- has: | ||||||||||
stopBy: neighbor | ||||||||||
kind: identifier | ||||||||||
regex: "^CryptoJS$" | ||||||||||
- has: | ||||||||||
stopBy: neighbor | ||||||||||
kind: property_identifier | ||||||||||
any: | ||||||||||
- regex: "^DES$" | ||||||||||
- regex: "^TripleDES$" | ||||||||||
- has: | ||||||||||
stopBy: neighbor | ||||||||||
kind: property_identifier | ||||||||||
any: | ||||||||||
- regex: "^encrypt$" | ||||||||||
- regex: "^decrypt$" | ||||||||||
rule: | ||||||||||
kind: call_expression | ||||||||||
any: | ||||||||||
- matches: MATCH_DES_USAGE |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||
id: chmod-permissions-typescript | ||||||||||||
severity: warning | ||||||||||||
language: typescript | ||||||||||||
message: >- | ||||||||||||
Do not give 777 permissions to a file. Always make sure you restrict the | ||||||||||||
permissions of your application files. Applications should not allow write | ||||||||||||
and execution for other users. | ||||||||||||
note: >- | ||||||||||||
[CWE-732] Incorrect Permission Assignment for Critical Resource. | ||||||||||||
ast-grep-essentials: true | ||||||||||||
utils: | ||||||||||||
MATCH_CHMOD_777: | ||||||||||||
kind: call_expression | ||||||||||||
all: | ||||||||||||
- has: | ||||||||||||
stopBy: neighbor | ||||||||||||
kind: member_expression | ||||||||||||
has: | ||||||||||||
stopBy: neighbor | ||||||||||||
kind: property_identifier | ||||||||||||
any: | ||||||||||||
- regex: "^chmod$" | ||||||||||||
- regex: "^chmodSync$" | ||||||||||||
- has: | ||||||||||||
stopBy: neighbor | ||||||||||||
kind: arguments | ||||||||||||
all: | ||||||||||||
- has: | ||||||||||||
stopBy: neighbor | ||||||||||||
kind: number | ||||||||||||
regex: "^0o777$" | ||||||||||||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Broaden the numeric-mode pattern - regex: "^0o777$"
+ # Accept 777 expressed as 0o777, 0o0777, 0o000777, or plain 777
+ regex: "^(0o0*777|777)$" This reduces false-negatives without widening scope excessively. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||
rule: | ||||||||||||
kind: call_expression | ||||||||||||
any: | ||||||||||||
- matches: MATCH_CHMOD_777 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove trailing whitespace on the new blank line to satisfy YAMLlint
YAMLlint flags
trailing-spaces
on this newly-added line. Strip the whitespace but keep the terminating newline to retain the intended EOF newline without breaking CI.📝 Committable suggestion
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 262-262: trailing spaces
(trailing-spaces)
🤖 Prompt for AI Agents