Skip to content

Commit 195629e

Browse files
author
Sakshis
committed
modification in express-session-hardcoded-secret-typescript
1 parent 3d5b961 commit 195629e

File tree

3 files changed

+293
-134
lines changed

3 files changed

+293
-134
lines changed

rules/typescript/security/express-session-hardcoded-secret-typescript.yml

Lines changed: 132 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -11,140 +11,145 @@ note: >-
1111
[CWE-798] Use of Hard-coded Credentials.
1212
[REFERENCES]
1313
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
14-
utils:
15-
MATCH_SECRET:
16-
kind: pair
17-
pattern: $C
18-
inside:
14+
rule:
15+
kind: pair
16+
all:
17+
- has:
18+
kind: property_identifier
19+
regex: ^secret$
20+
nthChild: 1
21+
- has:
22+
kind: string
23+
nthChild: 2
24+
inside:
25+
stopBy: end
26+
kind: object
27+
pattern: $OBJECT
28+
any:
29+
- inside:
30+
stopBy: end
31+
kind: call_expression
32+
pattern: $APP.use($SESSION($OBJECT))
33+
inside:
1934
stopBy: end
20-
kind: lexical_declaration
21-
all:
22-
- has:
23-
stopBy: end
24-
kind: variable_declarator
25-
has:
26-
stopBy: end
27-
kind: object
28-
has:
29-
stopBy: end
30-
kind: pair
31-
pattern: $C
32-
all:
33-
- has:
34-
stopBy: end
35-
kind: property_identifier
36-
pattern: $S
37-
- has:
38-
stopBy: end
39-
kind: string
40-
has:
41-
stopBy: end
42-
kind: string_fragment
43-
35+
follows:
36+
stopBy: end
37+
any:
38+
- kind: import_statement
39+
all:
40+
- has:
41+
kind: import_clause
42+
any:
43+
- has:
44+
kind: namespace_import
45+
has:
46+
kind: identifier
47+
pattern: $SESSION
48+
- has:
49+
kind: named_imports
50+
has:
51+
kind: import_specifier
52+
pattern: $SESSION
53+
- has:
54+
kind: identifier
55+
pattern: $SESSION
56+
- has:
57+
kind: string
58+
nthChild: 2
59+
regex: ^'express-session'$
4460
- any:
45-
- follows:
46-
stopBy: end
47-
kind: import_statement
48-
all:
49-
- has:
50-
stopBy: end
51-
kind: import_clause
52-
has:
53-
stopBy: neighbor
54-
kind: identifier
55-
pattern: $T
56-
- has:
57-
stopBy: neighbor
58-
kind: string
59-
has:
60-
stopBy: neighbor
61-
kind: string_fragment
62-
regex: '^express-session$'
63-
64-
- follows:
65-
stopBy: end
66-
kind: expression_statement
67-
has:
68-
stopBy: end
69-
kind: assignment_expression
70-
has:
71-
stopBy: end
72-
kind: call_expression
73-
all:
74-
- has:
75-
stopBy: neighbor
76-
kind: identifier
77-
regex: '^require$'
78-
- has:
79-
stopBy: end
80-
kind: arguments
81-
has:
82-
stopBy: neighbor
83-
kind: string
84-
has:
85-
stopBy: neighbor
86-
kind: string_fragment
87-
regex: '^express-session$'
88-
89-
- follows:
90-
stopBy: end
91-
kind: import_statement
92-
all:
61+
- kind: lexical_declaration
62+
all:
63+
- has:
64+
kind: variable_declarator
65+
all:
9366
- has:
94-
stopBy: neighbor
95-
kind: import_clause
96-
has:
97-
stopBy: neighbor
98-
kind: namespace_import
99-
has:
100-
stopBy: neighbor
101-
kind: identifier
102-
pattern: $T
67+
kind: identifier
68+
pattern: $SESSION
69+
nthChild: 1
10370
- has:
104-
stopBy: neighbor
105-
kind: string
106-
has:
107-
stopBy: neighbor
108-
kind: string_fragment
109-
regex: '^express-session$'
110-
111-
MATCH_SECRET_with_Instance:
112-
kind: pair
113-
all:
114-
- has:
115-
stopBy: neighbor
116-
kind: property_identifier
117-
regex: ^secret$
118-
- has:
119-
stopBy: neighbor
71+
kind: call_expression
72+
nthChild: 2
73+
regex: ^require\('express-session'\)$
74+
- kind: expression_statement
75+
has:
76+
kind: assignment_expression
77+
all:
78+
- has:
79+
kind: identifier
80+
pattern: $SESSION
81+
nthChild: 1
82+
- has:
83+
kind: call_expression
84+
nthChild: 2
85+
regex: ^require\('express-session'\)$
86+
87+
- inside:
88+
stopBy: end
89+
any:
90+
- kind: lexical_declaration
91+
- kind: expression_statement
92+
- kind: assignment_expression
93+
precedes:
94+
stopBy: end
95+
has:
96+
stopBy: end
97+
kind: call_expression
98+
pattern: $APP.use($SESSION($IDENTIFIER))
99+
has:
100+
stopBy: end
120101
kind: identifier
121-
pattern: $SECRET
122-
- inside:
102+
pattern: $IDENTIFIER
103+
inside:
123104
stopBy: end
124-
kind: expression_statement
125105
follows:
126106
stopBy: end
127-
kind: lexical_declaration
128-
has:
129-
stopBy: end
130-
kind: variable_declarator
131-
all:
107+
any:
108+
- kind: import_statement
109+
all:
132110
- has:
133-
stopBy: neighbor
134-
kind: identifier
135-
pattern: $SECRET
111+
kind: import_clause
112+
any:
113+
- has:
114+
kind: namespace_import
115+
has:
116+
kind: identifier
117+
pattern: $SESSION
118+
- has:
119+
kind: named_imports
120+
has:
121+
kind: import_specifier
122+
pattern: $SESSION
123+
- has:
124+
kind: identifier
125+
pattern: $SESSION
136126
- has:
137-
stopBy: neighbor
138-
kind: string
139-
has:
140-
stopBy: neighbor
141-
kind: string_fragment
142-
rule:
143-
kind: pair
144-
any:
145-
- matches: MATCH_SECRET
146-
- matches: MATCH_SECRET_with_Instance
147-
148-
constraints:
149-
S:
150-
regex: '^secret$'
127+
kind: string
128+
nthChild: 2
129+
regex: ^'express-session'$
130+
- any:
131+
- kind: lexical_declaration
132+
all:
133+
- has:
134+
kind: variable_declarator
135+
all:
136+
- has:
137+
kind: identifier
138+
pattern: $SESSION
139+
nthChild: 1
140+
- has:
141+
kind: call_expression
142+
nthChild: 2
143+
regex: ^require\('express-session'\)$
144+
- kind: expression_statement
145+
has:
146+
kind: assignment_expression
147+
all:
148+
- has:
149+
kind: identifier
150+
pattern: $SESSION
151+
nthChild: 1
152+
- has:
153+
kind: call_expression
154+
nthChild: 2
155+
regex: ^require\('express-session'\)$

0 commit comments

Comments
 (0)