-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathfind_sec_bugs.yml
2907 lines (2906 loc) · 103 KB
/
find_sec_bugs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# This file is part of Betterscan CE (Community Edition).
#
# Betterscan is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Betterscan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Betterscan. If not, see <https://www.gnu.org/licenses/>.
#
# Originally licensed under the BSD-3-Clause license with parts changed under
# LGPL v2.1 with Commons Clause.
# See the original LICENSE file for details.
#
# yamllint disable
# rule-set version: v1.0.44
# yamllint enable
---
rules:
- id: "find_sec_bugs.HTTPONLY_COOKIE-1"
pattern-either:
- patterns:
- pattern: |
javax.servlet.http.Cookie $C = new Cookie(..., ...);
...
(HttpServletResponse $RESP).addCookie($C);
- pattern-not-inside: |
javax.servlet.http.Cookie $C = new Cookie(..., ...);
...
$C.setHttpOnly(true);
...
(HttpServletResponse $RESP).addCookie($C);
- pattern: "(javax.servlet.http.Cookie $C).setHttpOnly(false);"
message: |
A new cookie is created without the HttpOnly flag set. The HttpOnly flag is a directive to the
browser to make sure that the cookie can not be red by malicious script. When a user is the
target of a "Cross-Site Scripting", the attacker would benefit greatly from getting the session
id for example.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag"
technology:
- "java"
- id: "find_sec_bugs.INSECURE_COOKIE-1"
pattern-either:
- patterns:
- pattern: |
javax.servlet.http.Cookie $C = new Cookie(..., ...);
...
(HttpServletResponse $RESP).addCookie($C);
- pattern-not-inside: |
javax.servlet.http.Cookie $C = new Cookie(..., ...);
...
$C.setSecure(true);
...
(HttpServletResponse $RESP).addCookie($C);
- pattern: "(javax.servlet.http.Cookie $C).setSecure(false);"
message: |
"Storing sensitive data in a persistent cookie for an extended period can lead to a breach of
confidentiality or account compromise."
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-539: Information Exposure Through Persistent Cookies"
technology:
- "java"
- id: "find_sec_bugs.COOKIE_PERSISTENT-1"
patterns:
- pattern-inside: |
(javax.servlet.http.Cookie $C).setMaxAge($AGE);
- metavariable-comparison:
metavariable: "$AGE"
comparison: "$AGE >= 31536000"
message: |
A new cookie is created without the Secure flag set. The Secure flag is a directive to the
browser to make sure that the cookie is not sent for insecure communication (http://)
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-614: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute"
technology:
- "java"
- id: "find_sec_bugs.COOKIE_USAGE-1"
patterns:
- pattern-inside: |
$FUNC(..., HttpServletRequest $REQ, ...) {
...
}
- pattern-either:
- patterns:
- pattern-inside: |
for (Cookie $C : $REQ.getCookies()) {
...
}
- pattern-either:
- pattern: "$C.getName();"
- pattern: "$C.getValue();"
- pattern: "$C.getPath();"
- pattern: "(Cookie $COOKIE).getName();"
- pattern: "(Cookie $COOKIE).getValue();"
- pattern: "(Cookie $COOKIE).getPath();"
message: |
The information stored in a custom cookie should not be sensitive or related to the session.
In most cases, sensitive data should only be stored in session and referenced by the user's
session cookie.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-614: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute"
technology:
- "java"
- id: "find_sec_bugs.HTTP_RESPONSE_SPLITTING-1"
mode: "taint"
pattern-sources:
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getParameter(...);"
pattern-sanitizers:
- patterns:
- pattern-inside: |
$STR.replaceAll("$REPLACE_CHAR", "$REPLACER");
...
- pattern: "$STR"
- metavariable-regex:
metavariable: "$REPLACER"
regex: ".*^(CRLF).*"
- metavariable-regex:
metavariable: "$REPLACE_CHAR"
regex: "(*CRLF)"
- pattern: "org.apache.commons.text.StringEscapeUtils.unescapeJava(...);"
pattern-sinks:
- pattern: "new javax.servlet.http.Cookie(\"$KEY\", ...);"
- patterns:
- pattern-inside: |
$C = new javax.servlet.http.Cookie("$KEY", ...);
...
- pattern: "$C.setValue(...);"
message: |
When an HTTP request contains unexpected CR and LF characters, the server may respond with an
output stream that is interpreted as two different HTTP responses (instead of one). An attacker
can control the second response and mount attacks such as cross-site scripting and cache
poisoning attacks.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP
Response Splitting')"
technology:
- "java"
- id: "find_sec_bugs.HRS_REQUEST_PARAMETER_TO_COOKIE-1"
mode: "taint"
pattern-sources:
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getParameter(...);"
pattern-sanitizers:
- patterns:
- pattern-inside: |
$STR.replaceAll("$REPLACE_CHAR", "$REPLACER");
...
- pattern: "$STR"
- metavariable-regex:
metavariable: "$REPLACER"
regex: ".*^(CRLF).*"
- metavariable-regex:
metavariable: "$REPLACE_CHAR"
regex: "(*CRLF)"
- pattern: "org.apache.commons.text.StringEscapeUtils.unescapeJava(...);"
pattern-sinks:
- pattern: "new javax.servlet.http.Cookie(\"$KEY\", ...);"
- patterns:
- pattern-inside: |
$C = new javax.servlet.http.Cookie("$KEY", ...);
...
- pattern: "$C.setValue(...);"
message: |
This code constructs an HTTP Cookie using an untrusted HTTP parameter. If this cookie is added
to an HTTP response, it will allow a HTTP response splitting vulnerability. See
http://en.wikipedia.org/wiki/HTTP_response_splitting for more information.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP
Response Splitting')"
technology:
- "java"
- id: "find_sec_bugs.HRS_REQUEST_PARAMETER_TO_HTTP_HEADER-1"
mode: "taint"
pattern-sources:
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getParameter(...);"
pattern-sanitizers:
- patterns:
- pattern-inside: |
$STR.replaceAll("$REPLACE_CHAR", "$REPLACER");
...
- pattern: "$STR"
- metavariable-regex:
metavariable: "$REPLACER"
regex: ".*^(CRLF).*"
- metavariable-regex:
metavariable: "$REPLACE_CHAR"
regex: "(*CRLF)"
- pattern: "org.apache.commons.text.StringEscapeUtils.unescapeJava(...);"
pattern-sinks:
- pattern: "(javax.servlet.http.HttpServletResponse $RES).setHeader(\"$KEY\", ...);"
- pattern: "(javax.servlet.http.HttpServletResponse $RES).addHeader(\"$KEY\", ...);"
- pattern: "(javax.servlet.http.HttpServletResponseWrapper $WRP).setHeader(\"$KEY\",
...);"
- pattern: "(javax.servlet.http.HttpServletResponseWrapper $WRP).addHeader(\"$KEY\",
...);"
message: |
This code directly writes an HTTP parameter to an HTTP header, which allows for a HTTP
response splitting vulnerability. See http://en.wikipedia.org/wiki/HTTP_response_splitting for
more information.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP
Response Splitting')"
technology:
- "java"
- id: "find_sec_bugs.TRUST_BOUNDARY_VIOLATION-1"
patterns:
- pattern-either:
- patterns:
- pattern: "(HttpServletRequest $H). ... .setAttribute($ARG1, $ARG2);"
- pattern-not: "(HttpServletRequest $H). ... .setAttribute(\"...\", \"...\");"
- patterns:
- pattern: "(HttpServletRequest $H). ... .putValue($ARG1, $ARG2);"
- pattern-not: "(HttpServletRequest $H). ... .putValue(\"...\", \"...\");"
languages:
- "java"
message: |
A trust boundary can be thought of as line drawn through a program. On one side
of the line, data is untrusted. On the other side of the line, data is assumed
to be trustworthy. The purpose of validation logic is to allow data to safely
cross the trust boundary - to move from untrusted to trusted. A trust boundary
violation occurs when a program blurs the line between what is trusted and what
is untrusted. By combining trusted and untrusted data in the same data
structure, it becomes easier for programmers to mistakenly trust unvalidated
data.
metadata:
category: "security"
cwe: "CWE-501: Trust Boundary Violation"
severity: "WARNING"
- id: "find_sec_bugs.PERMISSIVE_CORS-1"
patterns:
- pattern-either:
- pattern: "(HttpServletResponse $RES).setHeader(\"$HEADER\", \"$VAL\")"
- pattern: "(HttpServletResponse $RES).addHeader(\"$HEADER\", \"$VAL\")"
- metavariable-regex:
metavariable: "$HEADER"
regex: "(?i)(Access-Control-Allow-Origin)"
- metavariable-regex:
metavariable: "$VAL"
regex: "(\\*|null)"
message: |
Prior to HTML5, Web browsers enforced the Same Origin Policy which ensures that in order for
JavaScript to access the contents of a Web page, both the JavaScript and the Web page must
originate from the same domain. Without the Same Origin Policy, a malicious website could serve
up JavaScript that loads sensitive information from other websites using a client's
credentials, cull through it, and communicate it back to the attacker. HTML5 makes it possible
for JavaScript to access data across domains if a new HTTP header called
Access-Control-Allow-Origin is defined. With this header, a Web server defines which other
domains are allowed to access its domain using cross-origin requests. However, caution should
be taken when defining the header because an overly permissive CORS policy will allow a
malicious application to communicate with the victim application in an inappropriate way,
leading to spoofing, data theft, relay and other attacks.
languages:
- "java"
severity: "ERROR"
metadata:
cwe: "CWE-942: Permissive Cross-domain Policy with Untrusted Domains"
category: "security"
technology:
- "java"
- id: "find_sec_bugs.PERMISSIVE_CORS-2"
mode: "taint"
pattern-sources:
- pattern: "(HttpServletRequest $REQ).getParamater(...)"
pattern-sinks:
- patterns:
- pattern-either:
- pattern: "(HttpServletResponse $RES).setHeader(\"$HEADER\", ...)"
- pattern: "(HttpServletResponse $RES).addHeader(\"$HEADER\", ...)"
- metavariable-regex:
metavariable: "$HEADER"
regex: "(?i)(Access-Control-Allow-Origin)"
message: |
Prior to HTML5, Web browsers enforced the Same Origin Policy which ensures that in order for
JavaScript to access the contents of a Web page, both the JavaScript and the Web page must
originate from the same domain. Without the Same Origin Policy, a malicious website could serve
up JavaScript that loads sensitive information from other websites using a client's
credentials, cull through it, and communicate it back to the attacker. HTML5 makes it possible
for JavaScript to access data across domains if a new HTTP header called
Access-Control-Allow-Origin is defined. With this header, a Web server defines which other
domains are allowed to access its domain using cross-origin requests. However, caution should
be taken when defining the header because an overly permissive CORS policy will allow a
malicious application to communicate with the victim application in an inappropriate way,
leading to spoofing, data theft, relay and other attacks.
languages:
- "java"
severity: "ERROR"
metadata:
cwe: "CWE-942: Permissive Cross-domain Policy with Untrusted Domains"
category: "security"
technology:
- "java"
- id: "find_sec_bugs.BLOWFISH_KEY_SIZE-1"
patterns:
- pattern-inside: |
$KEYGEN = javax.crypto.KeyGenerator.getInstance("Blowfish", ...);
...
$KEYGEN.init($KEY_SIZE);
- metavariable-comparison:
metavariable: "$KEY_SIZE"
comparison: "$KEY_SIZE < 128"
message: |
A small key size makes the ciphertext vulnerable to brute force attacks. At least 128 bits of
entropy should be used when generating the key if use of Blowfish is required.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-326: Inadequate Encryption Strength"
technology:
- "java"
- id: "find_sec_bugs.DES_USAGE-1"
patterns:
- pattern-inside: |-
javax.crypto.Cipher.getInstance("$ALG")
- metavariable-regex:
metavariable: "$ALG"
regex: "^(DES)/.*"
message: |
DES is considered strong ciphers for modern applications. Currently, NIST recommends the usage
of AES block ciphers instead of DES.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-326: Inadequate Encryption Strength"
technology:
- "java"
- id: "find_sec_bugs.TDES_USAGE-1"
patterns:
- pattern-inside: |-
javax.crypto.Cipher.getInstance("$ALG")
- metavariable-regex:
metavariable: "$ALG"
regex: "^(DESede)/.*"
message: |
Triple DES (also known as 3DES or DESede) is considered strong ciphers for modern
applications. NIST recommends the usage of AES block ciphers instead of 3DES.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-326: Inadequate Encryption Strength"
technology:
- "java"
- id: "find_sec_bugs.ECB_MODE-1"
patterns:
- pattern-inside: |-
javax.crypto.Cipher.getInstance("...")
- pattern-regex: "(AES|DES(ede)?)(/ECB/*)"
message: |
An authentication cipher mode which provides better confidentiality of the encrypted data
should be used instead of Electronic Code Book (ECB) mode, which does not provide good
confidentiality. Specifically, ECB mode produces the same output for the same input each time.
This allows an attacker to intercept and replay the data.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-326: Inadequate Encryption Strength"
technology:
- "java"
- id: "find_sec_bugs.CIPHER_INTEGRITY-1"
patterns:
- pattern-inside: |-
javax.crypto.Cipher.getInstance("...")
- pattern-either:
- pattern-regex: "(/CBC/PKCS5Padding)"
- pattern-regex: "(AES|DES(ede)?)(/ECB/*)"
- pattern-not-regex: ".*/(CCM|CWC|OCB|EAX|GCM)/.*"
- pattern-not-regex: "^(RSA)/.*"
- pattern-not-regex: "^(ECIES)$"
message: |
The ciphertext produced is susceptible to alteration by an adversary. This mean that the
cipher provides no way to detect that the data has been tampered with. If the ciphertext can be
controlled by an attacker, it could be altered without detection.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-353: Missing Support for Integrity Check"
technology:
- "java"
- id: "find_sec_bugs.PADDING_ORACLE-1"
patterns:
- pattern-inside: |-
javax.crypto.Cipher.getInstance("...")
- pattern-regex: "(/CBC/PKCS5Padding)"
- pattern-not-regex: "^(RSA)/.*"
- pattern-not-regex: "^(ECIES)$"
message: |
This specific mode of CBC with PKCS5Padding is susceptible to padding oracle attacks. An
adversary could potentially decrypt the message if the system exposed the difference between
plaintext with invalid padding or valid padding. The distinction between valid and invalid
padding is usually revealed through distinct error messages being returned for each condition.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-696: Incorrect Behavior Order"
technology:
- "java"
- id: "find_sec_bugs.CUSTOM_MESSAGE_DIGEST-1"
patterns:
- pattern: |
class $CLAZZ extends java.security.MessageDigest {
...
}
message: |
Implementing a custom MessageDigest is error-prone. National Institute of Standards and
Technology(NIST) recommends the use of SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, or
SHA-512/256.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
technology:
- "java"
- id: "find_sec_bugs.DEFAULT_HTTP_CLIENT-1"
patterns:
- pattern: "new org.apache.http.impl.client.DefaultHttpClient(...);"
message: |
DefaultHttpClient with default constructor is not compatible with TLS 1.2
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
technology:
- "java"
- id: "find_sec_bugs.HAZELCAST_SYMMETRIC_ENCRYPTION-1"
patterns:
- pattern: "new com.hazelcast.config.SymmetricEncryptionConfig()"
message: |
The network communications for Hazelcast is configured to use a symmetric cipher (probably DES
or Blowfish). Those ciphers alone do not provide integrity or secure authentication. The use of
asymmetric encryption is preferred.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-326: Inadequate Encryption Strength"
technology:
- "java"
- id: "find_sec_bugs.RSA_KEY_SIZE-1"
patterns:
- pattern-either:
- patterns:
- pattern-inside: |
$GEN = KeyPairGenerator.getInstance($ALG, ...);
...
- pattern-either:
- pattern: "$VAR.initialize($SIZE, ...);"
- pattern: "new java.security.spec.RSAKeyGenParameterSpec($SIZE,...);"
- metavariable-comparison:
metavariable: "$SIZE"
comparison: "$SIZE < 2048"
- metavariable-regex:
metavariable: "$ALG"
regex: "\"(RSA|DSA)\""
message: |
Detected an insufficient key size for DSA. NIST recommends a key size
of 2048 or higher.
metadata:
category: "security"
cwe: "CWE-326: Inadequate Encryption Strength"
severity: "WARNING"
languages:
- "java"
- id: "find_sec_bugs.NULL_CIPHER-1"
pattern: "new javax.crypto.NullCipher()"
message: |
The NullCipher implements the Cipher interface by returning ciphertext identical to the
supplied plaintext. In a few contexts, such as testing, a NullCipher may be appropriate. Avoid
using the NullCipher. Its accidental use can introduce a significant confidentiality risk.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
technology:
- "java"
- id: "find_sec_bugs.RSA_NO_PADDING-1"
patterns:
- pattern: "javax.crypto.Cipher.getInstance($ALG,...);"
- metavariable-regex:
metavariable: "$ALG"
regex: ".*NoPadding.*"
message: |
The software uses the RSA algorithm but does not incorporate Optimal Asymmetric
Encryption Padding (OAEP), which might weaken the encryption.
metadata:
cwe: "CWE-780: Use of RSA Algorithm without OAEP"
severity: "WARNING"
languages:
- "java"
- id: "find_sec_bugs.WEAK_MESSAGE_DIGEST_MD5-1.WEAK_MESSAGE_DIGEST_SHA1-1"
patterns:
- pattern-either:
- pattern: "MessageDigest.getInstance($ALG, ...)"
- pattern: "Signature.getInstance($ALG, ...)"
- metavariable-regex:
metavariable: "$ALG"
regex: ".*(MD5|MD4|MD2|SHA1|SHA-1).*"
message: |
DES is considered strong ciphers for modern applications. Currently, NIST recommends the usage
of AES block ciphers instead of DES.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-326: Inadequate Encryption Strength"
technology:
- "java"
- id: "find_sec_bugs.SSL_CONTEXT-1"
patterns:
- pattern-either:
- pattern: "new org.apache.http.impl.client.DefaultHttpClient();"
- pattern: "javax.net.ssl.SSLContext.getInstance(\"SSL\");"
message: |
A HostnameVerifier that accept any host are often use because of certificate
reuse on many hosts. As a consequence, this is vulnerable to Man-in-the-middleattacks
attacks since the client will trust any certificate.
metadata:
category: "security"
cwe: "CWE-295: Improper Certificate Validation"
severity: "WARNING"
languages:
- "java"
- id: "find_sec_bugs.SERVLET_PARAMETER-1.SERVLET_CONTENT_TYPE-1.SERVLET_SERVER_NAME-1.SERVLET_SESSION_ID-1.SERVLET_QUERY_STRING-1.SERVLET_HEADER-1.SERVLET_HEADER_REFERER-1.SERVLET_HEADER_USER_AGENT-1"
mode: "taint"
pattern-sources:
- pattern-either:
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getContentType(...)"
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getServerName(...)"
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getRequestedSessionId(...)"
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getParameterValues(...)"
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getParameterMap(...)"
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getParameterNames(...)"
- pattern: "(javax.servlet.http.HttpServletRequest $REQ).getParameter(...)"
pattern-sinks:
- pattern-either:
- pattern: "\"...\" + $PAR"
- pattern: "$PAR + \"...\""
languages:
- "java"
message: |
The Servlet can read GET and POST parameters from various methods. The
value obtained should be considered unsafe."
metadata:
category: "security"
cwe: "CWE-20: Improper Input Validation"
severity: "WARNING"
- id: "find_sec_bugs.JAXRS_ENDPOINT-1"
mode: "taint"
pattern-sources:
- patterns:
- pattern-inside: |
@javax.ws.rs.Path("...")
$TYPE $FUNC(..., $VAR, ...) {
...
}
- pattern: "$VAR"
pattern-sanitizers:
- patterns:
- pattern-inside: |
$STR.replaceAll("$REPLACE_CHAR", "$REPLACER");
...
- pattern: "$STR"
- metavariable-regex:
metavariable: "$REPLACER"
regex: ".*^(CRLF).*"
- metavariable-regex:
metavariable: "$REPLACE_CHAR"
regex: "(*CRLF)"
- pattern: "org.apache.commons.text.StringEscapeUtils.unescapeJava(...);"
pattern-sinks:
- pattern: "return ...;"
message: |
This method is part of a REST Web Service (JSR311). The security of this web service should be
analyzed; Authentication, if enforced, should be tested. Access control, if enforced, should be
tested. The inputs should be tracked for potential vulnerabilities. The communication should
ideally be over SSL.
languages:
- "java"
severity: "WARNING"
metadata:
category: "security"
cwe: "CWE-20: Improper Input Validation"
technology:
- "java"
- id: "find_sec_bugs.JAXWS_ENDPOINT-1"
mode: "taint"
pattern-sources:
- patterns:
- pattern-inside: |
@javax.jws.WebMethod(...)
$TYPE $FUNC(..., $VAR, ...) {
...
}
- pattern: "$VAR"
pattern-sanitizers:
- patterns:
- pattern-inside: |
$STR.replaceAll("$REPLACE_CHAR", "$REPLACER");
...
- pattern: "$STR"
- metavariable-regex:
metavariable: "$REPLACER"
regex: ".*^(CRLF).*"
- metavariable-regex:
metavariable: "$REPLACE_CHAR"
regex: "(*CRLF)"
- pattern: "org.apache.commons.text.StringEscapeUtils.unescapeJava(...);"
pattern-sinks:
- pattern: "return ...;"
message: |
This method is part of a SOAP Web Service (JSR224). The security of this web service should be
analyzed; Authentication, if enforced, should be tested. Access control, if enforced, should be
tested. The inputs should be tracked for potential vulnerabilities. The communication should
ideally be over SSL.
languages:
- "java"
severity: "INFO"
metadata:
category: "security"
cwe: "CWE-20: Improper Input Validation"
owasp: "OWASP: Cross-Site Request Forgery"
technology:
- "java"
- id: "find_sec_bugs.UNENCRYPTED_SOCKET-1.UNENCRYPTED_SERVER_SOCKET-1"
patterns:
- pattern: "new java.net.Socket(...)"
languages:
- "java"
message: |
Beyond using an SSL socket, you need to make sure your use of SSLSocketFactory
does all the appropriate certificate validation checks to make sure you are not
subject to man-in-the-middle attacks. Please read the OWASP Transport Layer
Protection Cheat Sheet for details on how to do this correctly.
metadata:
cwe: "CWE-319: Cleartext Transmission of Sensitive Information"
severity: "WARNING"
- id: "find_sec_bugs.UNVALIDATED_REDIRECT-1.URL_REWRITING-1"
patterns:
- pattern-either:
- patterns:
- pattern: "(HttpServletResponse $REQ).sendRedirect(...)"
- pattern-not: "(HttpServletResponse $REQ).sendRedirect(\"...\")"
- patterns:
- pattern: "(HttpServletResponse $REQ).addHeader(...)"
- pattern-not: "(HttpServletResponse $REQ).addHeader(\"...\", \"...\")"
- patterns:
- pattern: "(HttpServletResponse $REQ).encodeURL(...)"
- pattern-not: "(HttpServletResponse $REQ).encodeURL(\"...\")"
- patterns:
- pattern: "(HttpServletResponse $REQ).encodeRedirectUrl(...)"
- pattern-not: "(HttpServletResponse $REQ).encodeRedirectUrl(\"...\")"
languages:
- "java"
message: |
Unvalidated redirects occur when an application redirects a user to a
destination URL specified by a user supplied parameter that is not validated.
Such vulnerabilities can be used to facilitate phishing attacks.
metadata:
category: "security"
cwe: "CWE-601: URL Redirection to Untrusted Site ('Open Redirect')"
severity: "ERROR"
- id: "find_sec_bugs.WEAK_HOSTNAME_VERIFIER-1.WEAK_TRUST_MANAGER-1"
patterns:
- pattern-either:
- patterns:
- pattern-inside: |
class $V implements HostnameVerifier {
...
}
- pattern-inside: |
public boolean verify(...) {
...
}
- pattern: "return true;"
- patterns:
- pattern-inside: |
class $V implements X509TrustManager {
...
}
- pattern-either:
- pattern: "public void checkClientTrusted(...) {}"
- pattern: "public void checkServerTrusted(...) {}"
- pattern: |
public X509Certificate[] getAcceptedIssuers() {
...
return null;
}
languages:
- "java"
message: |
A HostnameVerifier that accept any host are often use because of certificate
reuse on many hosts. As a consequence, this is vulnerable to Man-in-the-middle
attacks since the client will trust any certificate.
metadata:
category: "security"
cwe: "CWE-295: Improper Certificate Validation"
severity: "WARNING"
- id: "find_sec_bugs.FILE_UPLOAD_FILENAME-1"
patterns:
- pattern-inside: |
$FUNC(..., HttpServletRequest $REQ, ... ) {
...
$FILES = (ServletFileUpload $SFU).parseRequest($REQ);
...
}
- pattern-inside: |
for(FileItem $ITEM : $FILES) {
...
}
- pattern: "$ITEM.getName()"
message: |
The filename provided by the FileUpload API can be tampered with by the client to reference
unauthorized files. The provided filename should be properly validated to ensure it's properly
structured, contains no unauthorized path characters (e.g., / \), and refers to an authorized
file.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path
Traversal')"
technology:
- "java"
- id: "find_sec_bugs.WEAK_FILENAMEUTILS-1"
patterns:
- pattern-inside: |
import static org.apache.commons.io.FilenameUtils;
...
- pattern-either:
- pattern: "normalize(...)"
- pattern: "getExtension(...)"
- pattern: "isExtensions(...)"
- pattern: "getName(...)"
- pattern: "getBaseName(...)"
- pattern: "org.apache.commons.io.FilenameUtils.normalize(...)"
- pattern: "org.apache.commons.io.FilenameUtils.getExtension(...)"
- pattern: "org.apache.commons.io.FilenameUtils.isExtensions(...)"
- pattern: "org.apache.commons.io.FilenameUtils.getName(...)"
- pattern: "org.apache.commons.io.FilenameUtils.getBaseName(...)"
message: |
A file is opened to read its content. The filename comes from an input
parameter. If an unfiltered parameter is passed to this file API, files from an
arbitrary filesystem location could be read.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path
Traversal')"
technology:
- "java"
- id: "find_sec_bugs.STRUTS_FORM_VALIDATION-1"
patterns:
- pattern-inside: |
class $CLASS extends $SC {
...
}
- metavariable-regex:
metavariable: "$SC"
regex: "(ActionForm|ValidatorForm)"
- pattern-not: "public void validate() { ... }"
languages:
- "java"
message: |
Form inputs should have minimal input validation. Preventive validation helps
provide defense in depth against a variety of risks.
metadata:
category: "security"
cwe: "CWE-20: Improper Input Validation"
severity: "WARNING"
- id: "find_sec_bugs.AWS_QUERY_INJECTION-1"
mode: "taint"
pattern-sources:
- patterns:
- pattern-inside: |
$FUNC(..., $VAR, ...) {
...
}
- pattern: "$VAR"
- patterns:
- pattern-inside: |
$FUNC(...) {
...
$VAR = ... + $X;
...
}
- pattern: "$VAR"
pattern-sinks:
- patterns:
- pattern-either:
- pattern-inside: |
$REQ = new SelectRequest($QUERY, ...);
...
$DB.select($REQ);
- pattern-inside: |
$DB.select(new SelectRequest($QUERY,...));
- pattern-inside: |
$DB.select((SelectRequest $SR).withSelectExpression($QUERY,...));
- pattern: "$QUERY"
- metavariable-pattern:
metavariable: "$DB"
pattern-either:
- pattern: "(AmazonSimpleDB $DB)"
- pattern: "(AmazonSimpleDBClient $DB)"
message: |
Constructing SimpleDB queries containing user input can allow an attacker to view unauthorized
records.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-943: Improper Neutralization of Special Elements in Data Query Logic"
technology:
- "java"
- id: "find_sec_bugs.BEAN_PROPERTY_INJECTION-1"
patterns:
- pattern-inside: |-
$TYPE $FUNC(..., HttpServletRequest $REQ, ...) { ... }
- pattern-either:
- pattern: |
$MAP.put(..., $REQ.getParameter(...));
...
$BEAN_UTIL.populate(..., $MAP);
- pattern: |
while (...) {
...
$MAP.put(..., $REQ.getParameterValues(...));
}
...
$BEAN_UTIL.populate(..., $MAP);
- metavariable-pattern:
metavariable: "$BEAN_UTIL"
pattern-either:
- pattern: "(BeanUtilsBean $B)"
- pattern: "new BeanUtilsBean()"
- pattern: "org.apache.commons.beanutils.BeanUtils"
message: |
An attacker can set arbitrary bean properties that can compromise system integrity. An
attacker can leverage this functionality to access special bean properties like
class.classLoader that will allow them to override system properties and potentially execute
arbitrary code.
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-15: External Control of System or Configuration Setting"
technology:
- "java"
- id: "find_sec_bugs.CRLF_INJECTION_LOGS-1"
patterns:
- pattern-either:
- pattern: |
$TAINTED = (HttpServletRequest $REQ).getParameter(...);
...
$LOGGER.$METHOD(...,$TAINTED,...);
- pattern: |
$TAINTED = (HttpServletRequest $REQ).getParameter(...);
...
$VAR = String.Format(..., $TAINTED,...);
...
$LOGGER.$METHOD(...,$VAR,...);
- pattern: |
$TAINTED = (HttpServletRequest $REQ).getParameter(...);
...
$LOGGER.$METHOD(...,String.Format(..., $TAINTED,...),...);
- pattern: |
$TAINTED = (HttpServletRequest $REQ).getParameter(...);
...
$VAR = ... + $TAINTED + ...;
...
$LOGGER.$METHOD(...,$VAR,...);
- pattern: |
$TAINTED = (HttpServletRequest $REQ).getParameter(...);
...
$LOGGER.$METHOD(...,... + $TAINTED + ...,...);
- metavariable-regex:
metavariable: "$METHOD"
regex: "(log|logp|logrb|entering|exiting|fine|finer|finest|info|debug|trace|warn|warning|config|error|severe)"
- metavariable-pattern:
metavariable: "$LOGGER"
pattern-either:
- pattern: "(Logger $LOG)"
- pattern: "org.pmw.tinylog.Logger"
- pattern: "org.apache.log4j.Logger"
- pattern: "org.apache.logging.log4j.Logger"
- pattern: "org.slf4j.Logger"
- pattern: "org.apache.commons.logging.Log"
- pattern: "java.util.logging.Logger"
message: |
When data from an untrusted source is put into a logger and not neutralized correctly, an
attacker could forge log entries or include malicious content. Inserted false entries could be
used to skew statistics, distract the administrator or even to implicate another party in the
commission of a malicious act. If the log file is processed automatically, the attacker can
render the file unusable by corrupting the format of the file or injecting unexpected
characters. An attacker may also inject code or other commands into the log file and take
advantage of a vulnerability in the log processing utility (e.g. command injection or XSS).
languages:
- "java"
severity: "ERROR"
metadata:
category: "security"
cwe: "CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')"
technology:
- "java"
- id: "find_sec_bugs.COMMAND_INJECTION-1"
pattern-either:
- patterns:
- pattern-inside: |
$FUNC(...,String $PARAM, ...) {
...
}
- pattern-either:
- pattern: "(Runtime $R).exec($PARAM,...);"
- patterns:
- pattern-either:
- pattern: |
$CMDARR = new String[]{"$SHELL",...,$PARAM,...};
...
(Runtime $R).exec($CMDARR,...);
- pattern: "(Runtime $R).exec(new String[]{\"$SHELL\",...,$PARAM,...}, ...);"
- pattern: "(Runtime $R).exec(java.util.String.format(\"...\", ...,$PARAM,...));"
- pattern: "(Runtime $R).exec((String $A) + (String $B));"
- metavariable-regex:
metavariable: "$SHELL"
regex: "(/.../)?(sh|bash|ksh|csh|tcsh|zsh)$"
- pattern-not: "(Runtime $R).exec(\"...\",\"...\",\"...\",...);"
- pattern-not: "(Runtime $R).exec(new String[]{\"...\",\"...\",\"...\",...},...);\n"
- patterns:
- pattern-inside: |
$FUNC(...,String $PARAM, ...) {
...
}
- pattern-either:
- pattern: "(ProcessBuilder $PB).command($PARAM,...);"
- patterns:
- pattern-either:
- pattern: "(ProcessBuilder $PB).command(\"$SHELL\",...,$PARAM,...);"
- pattern: |
$CMDARR = java.util.Arrays.asList("$SHELL",...,$PARAM,...);
...
(ProcessBuilder $PB).command($CMDARR,...);
- pattern: "(ProcessBuilder $PB).command(java.util.Arrays.asList(\"$SHELL\",...,$PARAM,...),...);"
- pattern: "(ProcessBuilder $PB).command(java.util.String.format(\"...\",
...,$PARAM,...));"