Skip to content

Commit 7d58b71

Browse files
author
Sakshis
committed
modification in express-session-hardcoded-secret-javascript
1 parent fd3e0cf commit 7d58b71

File tree

2 files changed

+48
-213
lines changed

2 files changed

+48
-213
lines changed

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

Lines changed: 33 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -108,148 +108,43 @@ utils:
108108
kind: string_fragment
109109
regex: '^express-session$'
110110

111-
MATCH_SECRET_INSIDE_APP:
112-
kind: pair
113-
pattern: $C
114-
inside:
115-
stopBy: end
116-
kind: expression_statement
117-
all:
118-
- has:
119-
stopBy: end
120-
kind: call_expression
121-
all:
122-
- has:
123-
stopBy: end
124-
kind: member_expression
125-
all:
126-
- has:
127-
stopBy: end
128-
kind: identifier
129-
- has:
130-
stopBy: end
131-
kind: property_identifier
132-
regex: '^use$'
133-
- has:
134-
stopBy: end
135-
kind: arguments
136-
has:
137-
stopBy: end
138-
kind: call_expression
139-
all:
140-
- has:
141-
stopBy: end
142-
kind: identifier
143-
pattern: $T
144-
- has:
145-
stopBy: end
146-
kind: object
147-
has:
148-
stopBy: end
149-
kind: pair
150-
pattern: $C
151-
all:
152-
- has:
153-
stopBy: end
154-
kind: property_identifier
155-
pattern: $S
156-
- any:
157-
- has:
158-
stopBy: neighbor
159-
kind: identifier
160-
- has:
161-
stopBy: neighbor
162-
kind: string
163-
164-
- any:
165-
- follows:
166-
stopBy: end
167-
kind: import_statement
168-
all:
169-
- has:
170-
stopBy: end
171-
kind: import_clause
172-
has:
173-
stopBy: neighbor
174-
kind: identifier
175-
pattern: $T
176-
- has:
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
120+
kind: identifier
121+
pattern: $SECRET
122+
- inside:
123+
stopBy: end
124+
kind: expression_statement
125+
follows:
126+
stopBy: end
127+
kind: lexical_declaration
128+
has:
129+
stopBy: end
130+
kind: variable_declarator
131+
all:
132+
- has:
133+
stopBy: neighbor
134+
kind: identifier
135+
pattern: $SECRET
136+
- has:
137+
stopBy: neighbor
138+
kind: string
139+
has:
177140
stopBy: neighbor
178-
kind: string
179-
has:
180-
stopBy: neighbor
181-
kind: string_fragment
182-
regex: '^express-session$'
183-
184-
- follows:
185-
stopBy: end
186-
kind: expression_statement
187-
has:
188-
stopBy: end
189-
kind: assignment_expression
190-
has:
191-
stopBy: end
192-
kind: call_expression
193-
all:
194-
- has:
195-
stopBy: neighbor
196-
kind: identifier
197-
regex: '^require$'
198-
- has:
199-
stopBy: end
200-
kind: arguments
201-
has:
202-
stopBy: neighbor
203-
kind: string
204-
has:
205-
stopBy: neighbor
206-
kind: string_fragment
207-
regex: '^express-session$'
208-
209-
- follows:
210-
stopBy: end
211-
kind: import_statement
212-
has:
213-
stopBy: end
214-
kind: import_clause
215-
all:
216-
- has:
217-
stopBy: end
218-
kind: named_imports
219-
has:
220-
stopBy: end
221-
kind: import_specifier
222-
has:
223-
stopBy: end
224-
kind: identifier
225-
pattern: $T
226-
227-
- follows:
228-
stopBy: end
229-
kind: import_statement
230-
all:
231-
- has:
232-
stopBy: neighbor
233-
kind: import_clause
234-
has:
235-
stopBy: neighbor
236-
kind: namespace_import
237-
has:
238-
stopBy: neighbor
239-
kind: identifier
240-
pattern: $T
241-
- has:
242-
stopBy: neighbor
243-
kind: string
244-
has:
245-
stopBy: neighbor
246-
kind: string_fragment
247-
regex: '^express-session$'
248-
rule:
141+
kind: string_fragment
142+
rule:
249143
kind: pair
250144
any:
251145
- matches: MATCH_SECRET
252-
- matches: MATCH_SECRET_INSIDE_APP
146+
- matches: MATCH_SECRET_with_Instance
147+
253148
constraints:
254149
S:
255150
regex: '^secret$'

tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@ snapshots:
1313
style: primary
1414
start: 73
1515
end: 82
16-
- source: app
17-
style: secondary
18-
start: 55
19-
end: 58
20-
- source: use
21-
style: secondary
22-
start: 59
23-
end: 62
24-
- source: app.use
25-
style: secondary
26-
start: 55
27-
end: 62
28-
- source: session
29-
style: secondary
30-
start: 63
31-
end: 70
3216
- source: secret
3317
style: secondary
3418
start: 73
@@ -37,70 +21,26 @@ snapshots:
3721
style: secondary
3822
start: 81
3923
end: 82
40-
- source: 'secret: a'
41-
style: secondary
42-
start: 73
43-
end: 82
44-
- source: |-
45-
{
46-
secret: a,
47-
resave: false,
48-
saveUninitialized: false,
49-
}
50-
style: secondary
51-
start: 71
52-
end: 126
53-
- source: |-
54-
session({
55-
secret: a,
56-
resave: false,
57-
saveUninitialized: false,
58-
})
59-
style: secondary
60-
start: 63
61-
end: 127
62-
- source: |-
63-
(session({
64-
secret: a,
65-
resave: false,
66-
saveUninitialized: false,
67-
}))
68-
style: secondary
69-
start: 62
70-
end: 128
71-
- source: |-
72-
app.use(session({
73-
secret: a,
74-
resave: false,
75-
saveUninitialized: false,
76-
}))
77-
style: secondary
78-
start: 55
79-
end: 128
80-
- source: session
81-
style: secondary
82-
start: 12
83-
end: 19
84-
- source: '* as session'
24+
- source: a
8525
style: secondary
86-
start: 7
87-
end: 19
88-
- source: '* as session'
26+
start: 47
27+
end: 48
28+
- source: a
8929
style: secondary
90-
start: 7
91-
end: 19
92-
- source: express-session
30+
start: 52
31+
end: 53
32+
- source: '''a'''
9333
style: secondary
94-
start: 26
95-
end: 41
96-
- source: '''express-session'''
34+
start: 51
35+
end: 54
36+
- source: a = 'a'
9737
style: secondary
98-
start: 25
99-
end: 42
100-
- source: import * as session from 'express-session'
38+
start: 47
39+
end: 54
40+
- source: let a = 'a'
10141
style: secondary
102-
start: 0
103-
end: 42
42+
start: 43
43+
end: 54
10444
- source: |-
10545
app.use(session({
10646
secret: a,

0 commit comments

Comments
 (0)