forked from arizon-dev/quickblaze-encrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.security-scan
2679 lines (2679 loc) · 112 KB
/
.security-scan
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
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "SnykCode",
"semanticVersion": "1.0.0",
"version": "1.0.0",
"rules": [
{
"id": "php/PT",
"name": "PT",
"shortDescription": {
"text": "Path Traversal"
},
"defaultConfiguration": {
"level": "error"
},
"help": {
"markdown": "## Details\n\nA Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with \"dot-dot-slash (../)\" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.\n\nDirectory Traversal vulnerabilities can be generally divided into two types:\n\n- **Information Disclosure**: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.\n\n`st` is a module for serving static files on web pages, and contains a [vulnerability of this type](https://snyk.io/vuln/npm:st:20140206). In our example, we will serve files from the `public` route.\n\nIf an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.\n\n```\ncurl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa\n```\n**Note** `%2e` is the URL encoded version of `.` (dot).\n\n- **Writing arbitrary files**: Allows the attacker to create or replace existing files. This type of vulnerability is also known as `Zip-Slip`.\n\nOne way to achieve this is by using a malicious `zip` archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.\n\nThe following is an example of a `zip` archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in `/root/.ssh/` overwriting the `authorized_keys` file:\n\n```\n2018-04-15 22:04:29 ..... 19 19 good.txt\n2018-04-15 22:04:42 ..... 20 20 ../../../../../../root/.ssh/authorized_keys\n```",
"text": ""
},
"properties": {
"tags": [
"php"
],
"categories": [
"Security"
],
"exampleCommitFixes": [
{
"commitURL": "https://github.com/pfsense/pfsense-packages/commit/0d2f8f00a6a442f5672e5fe8f62a1f4d21da6a9b?diff=split#diff-7d40bbc944bdd9d0ac99f1e375807fb3L98",
"lines": [
{
"line": "if (isset($_POST['upload'])) {",
"lineNumber": 96,
"lineChange": "none"
},
{
"line": " if ($_FILES[\"sidmods_fileup\"][\"error\"] == UPLOAD_ERR_OK) {",
"lineNumber": 97,
"lineChange": "none"
},
{
"line": " $tmp_name = $_FILES[\"sidmods_fileup\"][\"tmp_name\"];",
"lineNumber": 98,
"lineChange": "none"
},
{
"line": " $name = $_FILES[\"sidmods_fileup\"][\"name\"];",
"lineNumber": 99,
"lineChange": "removed"
},
{
"line": " $name = basename($_FILES[\"sidmods_fileup\"][\"name\"]);",
"lineNumber": 99,
"lineChange": "added"
},
{
"line": " move_uploaded_file($tmp_name, \"{$sidmods_path}{$name}\");",
"lineNumber": 100,
"lineChange": "none"
},
{
"line": " }",
"lineNumber": 101,
"lineChange": "none"
},
{
"line": " else",
"lineNumber": 102,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/ExchangeWorld/ExchangeWorld/commit/606aa8b3eb707f1cd1831fb663a8f415a463aa05?diff=split#diff-041d983df8c7b46dbc24f32fb39de8feL4",
"lines": [
{
"line": "<?php",
"lineNumber": 1,
"lineChange": "none"
},
{
"line": " include(\"../include/connect.php\");",
"lineNumber": 2,
"lineChange": "none"
},
{
"line": " $tmp_file_name = $_FILES['fileToUpload'];",
"lineNumber": 3,
"lineChange": "none"
},
{
"line": " $ok = move_uploaded_file($tmp_file_name, './images/database/'.$tmp_file_name);",
"lineNumber": 4,
"lineChange": "removed"
},
{
"line": " $ext = pathinfo($_FILES['fileToUpload'], PATHINFO_EXTENSION);",
"lineNumber": 4,
"lineChange": "added"
},
{
"line": " $new_file_name = date('Y-m-d_H-i-s');",
"lineNumber": 5,
"lineChange": "added"
},
{
"line": " $ok = move_uploaded_file($tmp_file_name, './images/database/'.$new_file_name.'.'.$ext);",
"lineNumber": 6,
"lineChange": "added"
},
{
"line": " // This message will be passed to 'oncomplete' function",
"lineNumber": 8,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/davgothic/AjaxFileUpload/commit/44e83f675387e1d67ce49f4c85f42868ab3037e9?diff=split#diff-33a35ae4a5af682c7a5d1508ce179a43L4",
"lines": [
{
"line": "<?php",
"lineNumber": 1,
"lineChange": "none"
},
{
"line": "if ($_FILES)",
"lineNumber": 7,
"lineChange": "none"
},
{
"line": "{",
"lineNumber": 8,
"lineChange": "none"
},
{
"line": "if (isset($_FILES['file1']))",
"lineNumber": 12,
"lineChange": "none"
},
{
"line": "{",
"lineNumber": 13,
"lineChange": "none"
},
{
"line": " $tmp_name\t= $_FILES['file1']['tmp_name'];",
"lineNumber": 14,
"lineChange": "none"
},
{
"line": " $name\t\t= $_FILES['file1']['name'];",
"lineNumber": 8,
"lineChange": "removed"
},
{
"line": " $name\t\t= basename($_FILES['file1']['name']);",
"lineNumber": 15,
"lineChange": "added"
},
{
"line": " $error\t\t= $_FILES['file1']['error'];",
"lineNumber": 16,
"lineChange": "none"
},
{
"line": " ",
"lineNumber": 17,
"lineChange": "none"
},
{
"line": " if ($error == 0)",
"lineNumber": 11,
"lineChange": "removed"
},
{
"line": "{",
"lineNumber": 19,
"lineChange": "none"
},
{
"line": " move_uploaded_file($tmp_name, $name);",
"lineNumber": 13,
"lineChange": "removed"
},
{
"line": " else",
"lineNumber": 26,
"lineChange": "added"
},
{
"line": " {",
"lineNumber": 27,
"lineChange": "added"
},
{
"line": " move_uploaded_file($tmp_name, $name);",
"lineNumber": 28,
"lineChange": "added"
},
{
"line": " }",
"lineNumber": 29,
"lineChange": "added"
},
{
"line": " }",
"lineNumber": 30,
"lineChange": "none"
},
{
"line": "}",
"lineNumber": 31,
"lineChange": "none"
}
]
}
],
"exampleCommitDescriptions": [
"add file upload feature"
],
"precision": "very-high",
"repoDatasetSize": 323,
"cwe": [
"CWE-23"
]
}
},
{
"id": "php/InsecureRandomData",
"name": "InsecureRandomData",
"shortDescription": {
"text": "Use of Insufficiently Random Values"
},
"defaultConfiguration": {
"level": "error"
},
"help": {
"markdown": "\n## Details\n\nComputer security relies on random numbers for many things: generating secure, confidential session keys; hashing password data; encryption for transmitting sensitive data, and more. It's easy to understand why. If session keys, for example, were generated sequentially, attackers would be able to guess these easily and then hijack legitimate user sessions. Similarly, if encryption techniques used easy-to-guess numbers, attackers could use brute-force attacks to gain unauthorized access.\n\nIn reality, since computers cannot generate truly random numbers, they use \"pseudorandom\" numbers instead, generated using an algorithm that is \"seeded\" in a variety of ways to produce highly variable values in a random-seeming order, making them very hard-in theory-for attackers to guess. However, if developers inadvertently make use of a weak random algorithm, attackers may be able to discover the algorithm, seed, or pattern, ultimately unlocking access to commands or sensitive data, which can then be held for ransom or sold.\n\n### Best practices for prevention\n* Avoid using weak pseudorandom number generators (PRNGs), such as statistical PRNGs. Instead, choose a cryptographically secure PRNG.\n* Avoid using predictable seed values, such as user ID or server start time. Instead, use a seed that is itself pseudorandom, such as one taken from an external hardware source.\n* Use standard, accepted security algorithms and libraries rather than taking a DIY approach and creating custom code that may contain inherent weaknesses or overlook critical flaws.\n* Use static analysis tools to identify potential instances of this weakness in code and then ensure good test coverage with appropriate white-box testing.\n* Educate developers about the importance of entropy in security systems development, and consider adopting tools that are FIPS 140-2 compliant.",
"text": ""
},
"properties": {
"tags": [
"php"
],
"categories": [
"Security"
],
"exampleCommitFixes": [],
"exampleCommitDescriptions": [],
"precision": "very-high",
"repoDatasetSize": 0,
"cwe": [
"CWE-330"
]
}
},
{
"id": "php/TooPermissiveCorsHeader",
"name": "TooPermissiveCorsHeader",
"shortDescription": {
"text": "Origin Validation Error"
},
"defaultConfiguration": {
"level": "warning"
},
"help": {
"markdown": "\n## Details\n\nAs a legacy of early web design and site limitations, most web applications default, for security reasons, to a \"same origin policy\". This means that browsers can only retrieve data from another site if the two sites share the same domain. In today's complex online environment, however, sites and applications often need to retrieve data from other domains. This is done under fairly limited conditions through an exception to the same origin policy known as \"cross-origin resource sharing\".\n\nDevelopers may create definitions of trusted domains that are broader than absolutely necessary, inadvertently opening up wider access than intended. This weakness could result in data exposure or loss, or even allow an attacker to take over the site or application.\n\n### Best practices for prevention\n* Avoid using wildcards for cross-origin resource sharing. Instead, define intended domains explicitly.\n* Ensure that your site or app is well defended against cross-site scripting attacks (XSS), which could lead to takeover via an overly permissive cross-domain policy.\n* Do not mix secure and insecure protocols when defining cross-domain policies.\n* Consider defining a clear approved list to specify which domains will be given resource-level access; use this approved list to validate all domain access requests.\n* Clearly define which methods (view, read, and update) are permitted for each resource and domain to avoid abuse.",
"text": ""
},
"properties": {
"tags": [
"php"
],
"categories": [
"Security"
],
"exampleCommitFixes": [
{
"commitURL": "https://github.com/Atheos/Atheos/commit/95fd657bc7330097169248760c3387f1d5f600c4?diff=split#diff-828e0013b8f3bc1bb22b4f57172b019dL3",
"lines": [
{
"line": "<?php",
"lineNumber": 1,
"lineChange": "removed"
},
{
"line": "header(\"Access-Control-Allow-Origin: *\");",
"lineNumber": 2,
"lineChange": "removed"
},
{
"line": " ",
"lineNumber": 12,
"lineChange": "none"
},
{
"line": " ",
"lineNumber": 29,
"lineChange": "none"
},
{
"line": "// header(\"Access-Control-Allow-Origin: *\");",
"lineNumber": 26,
"lineChange": "added"
},
{
"line": "header(\"strict-transport-security: max-age=600\");",
"lineNumber": 27,
"lineChange": "added"
},
{
"line": "\\ No newline at end of file",
"lineNumber": 55,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/gsavio/player-shoutcast-html5/commit/8c901ad4543f56b09f2295ef0c95b473b38c6571?diff=split#diff-f14f8bd7d8d03135fc0f4ff68b0a3521L133",
"lines": [
{
"line": " $array = ['error' => 'URL parameter not found'];",
"lineNumber": 130,
"lineChange": "none"
},
{
"line": "}",
"lineNumber": 131,
"lineChange": "none"
},
{
"line": "header('Access-Control-Allow-Origin: *');",
"lineNumber": 132,
"lineChange": "removed"
},
{
"line": "$urlHost = $_SERVER['HTTP_HOST'];",
"lineNumber": 133,
"lineChange": "added"
},
{
"line": "header('Access-Control-Allow-Origin: '.$urlHost);",
"lineNumber": 135,
"lineChange": "added"
},
{
"line": "header('Content-type: application/json', true);",
"lineNumber": 136,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/wgenial/cartrolandofc/commit/3d69f64001ffe84e89404bcd4ca627d2d1e95a33?diff=split#diff-5b9b7bac226602d432ba9969f7986f37L9",
"lines": [
{
"line": " */",
"lineNumber": 6,
"lineChange": "none"
},
{
"line": "header(\"Access-Control-Allow-Origin: *\");",
"lineNumber": 8,
"lineChange": "removed"
},
{
"line": "header('Content-type: application/json');",
"lineNumber": 9,
"lineChange": "removed"
},
{
"line": "header('Content-type: application/json;charset=UTF-8');",
"lineNumber": 8,
"lineChange": "added"
},
{
"line": " if (isset($_GET[\"api\"]) and $_GET[\"api\"] !== \"\") {",
"lineNumber": 11,
"lineChange": "none"
}
]
}
],
"exampleCommitDescriptions": [
"CORS added, DEMO constant deleted",
"added handling of response headers overrides by config"
],
"precision": "very-high",
"repoDatasetSize": 26,
"cwe": [
"CWE-942",
"CWE-346"
]
}
},
{
"id": "php/XSS",
"name": "XSS",
"shortDescription": {
"text": "Cross-site Scripting (XSS)"
},
"defaultConfiguration": {
"level": "error"
},
"help": {
"markdown": "## Details\n\nA cross-site scripting attack occurs when the attacker tricks a legitimate web-based application or site to accept a request as originating from a trusted source.\n\nThis is done by escaping the context of the web application; the web application then delivers that data to its users along with other trusted dynamic content, without validating it. The browser unknowingly executes malicious script on the client side (through client-side languages; usually JavaScript or HTML) in order to perform actions that are otherwise typically blocked by the browser's Same Origin Policy.\n\nInjecting malicious code is the most prevalent manner by which XSS is exploited; for this reason, escaping characters in order to prevent this manipulation is the top method for securing code against this vulnerability.\n\nEscaping means that the application is coded to mark key characters, and particularly key characters included in user input, to prevent those characters from being interpreted in a dangerous context. For example, in HTML, `<` can be coded as `<`; and `>` can be coded as `>`; in order to be interpreted and displayed as themselves in text, while within the code itself, they are used for HTML tags. If malicious content is injected into an application that escapes special characters and that malicious content uses `<` and `>` as HTML tags, those characters are nonetheless not interpreted as HTML tags by the browser if they've been correctly escaped in the application code and in this way the attempted attack is diverted.\n\nThe most prominent use of XSS is to steal cookies (source: OWASP HttpOnly) and hijack user sessions, but XSS exploits have been used to expose sensitive information, enable access to privileged services and functionality and deliver malware.\n\n### Types of attacks\nThere are a few methods by which XSS can be manipulated:\n\n|Type|Origin|Description|\n|--|--|--|\n|**Stored**|Server|The malicious code is inserted in the application (usually as a link) by the attacker. The code is activated every time a user clicks the link.|\n|**Reflected**|Server|The attacker delivers a malicious link externally from the vulnerable web site application to a user. When clicked, malicious code is sent to the vulnerable web site, which reflects the attack back to the user's browser.|\n|**DOM-based**|Client|The attacker forces the user's browser to render a malicious page. The data in the page itself delivers the cross-site scripting data.|\n|**Mutated**| |The attacker injects code that appears safe, but is then rewritten and modified by the browser, while parsing the markup. An example is rebalancing unclosed quotation marks or even adding quotation marks to unquoted parameters.|\n\n### Affected environments\nThe following environments are susceptible to an XSS attack:\n\n* Web servers\n* Application servers\n* Web application environments\n\n### How to prevent\nThis section describes the top best practices designed to specifically protect your code:\n\n* Sanitize data input in an HTTP request before reflecting it back, ensuring all data is validated, filtered or escaped before echoing anything back to the user, such as the values of query parameters during searches.\n* Convert special characters such as `?`, `&`, `/`, `<`, `>` and spaces to their respective HTML or URL encoded equivalents.\n* Give users the option to disable client-side scripts.\n* Redirect invalid requests.\n* Detect simultaneous logins, including those from two separate IP addresses, and invalidate those sessions.\n* Use and enforce a Content Security Policy (source: Wikipedia) to disable any features that might be manipulated for an XSS attack.\n* Read the documentation for any of the libraries referenced in your code to understand which elements allow for embedded HTML.",
"text": ""
},
"properties": {
"tags": [
"php"
],
"categories": [
"Security"
],
"exampleCommitFixes": [
{
"commitURL": "https://github.com/minkphp/Mink/commit/232919c0c44a2b35d410373c12db404b709ec25c?diff=split#diff-b51e2215d4bd4e189c9360d91a412970L6",
"lines": [
{
"line": " setcookie(\"tc\", $_POST['cookie_value'], null, '/');",
"lineNumber": 3,
"lineChange": "none"
},
{
"line": "} elseif (isset($_GET[\"show_value\"])) {",
"lineNumber": 4,
"lineChange": "none"
},
{
"line": " echo $_COOKIE[\"tc\"];",
"lineNumber": 5,
"lineChange": "removed"
},
{
"line": " echo htmlspecialchars($_COOKIE[\"tc\"], ENT_QUOTES, 'UTF-8');",
"lineNumber": 5,
"lineChange": "added"
},
{
"line": " die();",
"lineNumber": 6,
"lineChange": "none"
},
{
"line": "}",
"lineNumber": 7,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/yunluo/Git/commit/1cb7eddf43f770c055cd685c7f73bb3dac713789?diff=split#diff-34390932035b5d4fd059e5e9a4c629b6L69",
"lines": [
{
"line": " the_content(); ?>",
"lineNumber": 66,
"lineChange": "none"
},
{
"line": "<form class=\"googlo-tougao\" method=\"post\" action=\"<?php",
"lineNumber": 67,
"lineChange": "none"
},
{
"line": " echo $_SERVER[\"REQUEST_URI\"];",
"lineNumber": 68,
"lineChange": "removed"
},
{
"line": " echo htmlspecialchars($_SERVER[\"REQUEST_URI\"]);",
"lineNumber": 68,
"lineChange": "added"
},
{
"line": " $current_user = wp_get_current_user(); ?>\">",
"lineNumber": 69,
"lineChange": "none"
},
{
"line": "<div style=\"text-align: left; padding-top: 10px;\">",
"lineNumber": 70,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/railt/railt/commit/856e3456f6b87c94c1262a842c6df29a76cf9be1?diff=split#diff-eaa75d4030b62891c20b9f9d83a58fd2L59",
"lines": [
{
"line": " echo $request->get('schema');",
"lineNumber": 56,
"lineChange": "removed"
},
{
"line": " echo htmlspecialchars($request->get('schema'));",
"lineNumber": 73,
"lineChange": "added"
},
{
"line": " } else {",
"lineNumber": 74,
"lineChange": "none"
},
{
"line": " echo file_get_contents(__DIR__ . '/gql/schema.graphqls');",
"lineNumber": 58,
"lineChange": "removed"
},
{
"line": " echo htmlspecialchars(file_get_contents(__DIR__ . '/gql/schema.graphqls'));",
"lineNumber": 75,
"lineChange": "added"
},
{
"line": " }",
"lineNumber": 76,
"lineChange": "none"
},
{
"line": "?></div>",
"lineNumber": 77,
"lineChange": "none"
}
]
}
],
"exampleCommitDescriptions": [
"Uploaded files now appear on profile pages",
"Add files via upload",
"remove file name from output to avoid XSS"
],
"precision": "very-high",
"repoDatasetSize": 526,
"cwe": [
"CWE-79"
]
}
},
{
"id": "javascript/DOMXSS",
"name": "DOMXSS",
"shortDescription": {
"text": "Cross-site Scripting (XSS)"
},
"defaultConfiguration": {
"level": "error"
},
"help": {
"markdown": "## Details\n\nA cross-site scripting attack occurs when the attacker tricks a legitimate web-based application or site to accept a request as originating from a trusted source.\n\nThis is done by escaping the context of the web application; the web application then delivers that data to its users along with other trusted dynamic content, without validating it. The browser unknowingly executes malicious script on the client side (through client-side languages; usually JavaScript or HTML) in order to perform actions that are otherwise typically blocked by the browser's Same Origin Policy.\n\nInjecting malicious code is the most prevalent manner by which XSS is exploited; for this reason, escaping characters in order to prevent this manipulation is the top method for securing code against this vulnerability.\n\nEscaping means that the application is coded to mark key characters, and particularly key characters included in user input, to prevent those characters from being interpreted in a dangerous context. For example, in HTML, `<` can be coded as `<`; and `>` can be coded as `>`; in order to be interpreted and displayed as themselves in text, while within the code itself, they are used for HTML tags. If malicious content is injected into an application that escapes special characters and that malicious content uses `<` and `>` as HTML tags, those characters are nonetheless not interpreted as HTML tags by the browser if they've been correctly escaped in the application code and in this way the attempted attack is diverted.\n\nThe most prominent use of XSS is to steal cookies (source: OWASP HttpOnly) and hijack user sessions, but XSS exploits have been used to expose sensitive information, enable access to privileged services and functionality and deliver malware.\n\n### Types of attacks\nThere are a few methods by which XSS can be manipulated:\n\n|Type|Origin|Description|\n|--|--|--|\n|**Stored**|Server|The malicious code is inserted in the application (usually as a link) by the attacker. The code is activated every time a user clicks the link.|\n|**Reflected**|Server|The attacker delivers a malicious link externally from the vulnerable web site application to a user. When clicked, malicious code is sent to the vulnerable web site, which reflects the attack back to the user's browser.|\n|**DOM-based**|Client|The attacker forces the user's browser to render a malicious page. The data in the page itself delivers the cross-site scripting data.|\n|**Mutated**| |The attacker injects code that appears safe, but is then rewritten and modified by the browser, while parsing the markup. An example is rebalancing unclosed quotation marks or even adding quotation marks to unquoted parameters.|\n\n### Affected environments\nThe following environments are susceptible to an XSS attack:\n\n* Web servers\n* Application servers\n* Web application environments\n\n### How to prevent\nThis section describes the top best practices designed to specifically protect your code:\n\n* Sanitize data input in an HTTP request before reflecting it back, ensuring all data is validated, filtered or escaped before echoing anything back to the user, such as the values of query parameters during searches.\n* Convert special characters such as `?`, `&`, `/`, `<`, `>` and spaces to their respective HTML or URL encoded equivalents.\n* Give users the option to disable client-side scripts.\n* Redirect invalid requests.\n* Detect simultaneous logins, including those from two separate IP addresses, and invalidate those sessions.\n* Use and enforce a Content Security Policy (source: Wikipedia) to disable any features that might be manipulated for an XSS attack.\n* Read the documentation for any of the libraries referenced in your code to understand which elements allow for embedded HTML.",
"text": ""
},
"properties": {
"tags": [
"javascript"
],
"categories": [
"Security"
],
"exampleCommitFixes": [
{
"commitURL": "https://github.com/decred/dcrdata/commit/1996f027d9c1b64fafdc22baa26b58d27f374638?diff=split#diff-6d548c58846af1c8dadd7f36d75f2795L319",
"lines": [
{
"line": "var ctrl = this",
"lineNumber": 316,
"lineChange": "none"
},
{
"line": "ctrl.listboxTarget.classList.add('loading')",
"lineNumber": 317,
"lineChange": "none"
},
{
"line": "let tableResponse = await axios.get(ctrl.makeTableUrl(txType, count, offset))",
"lineNumber": 318,
"lineChange": "none"
},
{
"line": "let html = tableResponse.data",
"lineNumber": 319,
"lineChange": "none"
},
{
"line": "ctrl.tableTarget.innerHTML = html",
"lineNumber": 320,
"lineChange": "removed"
},
{
"line": "ctrl.tableTarget.innerHTML = dompurify.sanitize(html)",
"lineNumber": 301,
"lineChange": "added"
},
{
"line": "var settings = ctrl.listSettings",
"lineNumber": 321,
"lineChange": "none"
},
{
"line": "settings.n = count",
"lineNumber": 322,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/shokai/sinatra-template/commit/d4b6b31eea77cd39d387f515ced18f73b508854f?diff=split#diff-f485b1889bd3c96211c9236b0cf5daecL2",
"lines": [
{
"line": "};",
"lineNumber": 7,
"lineChange": "added"
},
{
"line": "$(function(){",
"lineNumber": 9,
"lineChange": "none"
},
{
"line": " $('input#start_btn').click(omikuji_start);",
"lineNumber": 10,
"lineChange": "none"
},
{
"line": "});",
"lineNumber": 11,
"lineChange": "none"
},
{
"line": "var omikuji_start = function(){",
"lineNumber": 13,
"lineChange": "none"
},
{
"line": " $.getJSON(omikuji_api, function(res){",
"lineNumber": 14,
"lineChange": "none"
},
{
"line": " console.log(res);",
"lineNumber": 15,
"lineChange": "none"
},
{
"line": " var li = $('<li>').append(res.result + ' - ' + res.time);",
"lineNumber": 8,
"lineChange": "removed"
},
{
"line": " var li = $('<li>').append(res.result.htmlEscape() + ' - ' + res.time.htmlEscape());",
"lineNumber": 16,
"lineChange": "added"
},
{
"line": " $('ul#results').prepend(li);",
"lineNumber": 17,
"lineChange": "none"
},
{
"line": " });",
"lineNumber": 18,
"lineChange": "none"
}
]
},
{
"commitURL": "https://github.com/ether/etherpad-lite/commit/83ce73b77b5061de2c1c24219b7bdc3ea499f7af?diff=split#diff-5800366247a45833e8dbfce86ea4d046L59",
"lines": [
{
"line": "//Check if we accessed the pad over https",
"lineNumber": 57,
"lineChange": "none"
},
{
"line": "var secure = window.location.protocol == \"https:\" ? \";secure\" : \"\";",
"lineNumber": 58,
"lineChange": "none"
},
{
"line": "//Check if the browser is IE and if so make sure the full path is set in the cookie",
"lineNumber": 60,
"lineChange": "none"
},
{
"line": " $(\"#editorloadingbox\").css(\"padding\", \"10px\");",
"lineNumber": 524,
"lineChange": "none"
},
{
"line": " $(\"#editorloadingbox\").css(\"padding-top\", \"45px\");",
"lineNumber": 525,
"lineChange": "none"
},
{
"line": " $(\"#editorloadingbox\").html(\"<div style='text-align:left;color:red;font-size:16px;'><b>An error occurred</b><br>The error was reported with the following id: '\" + errorId + \"'<br><br><span sty",
"lineNumber": 526,
"lineChange": "none"
},
{
"line": " + \"ErrorId: \" + errorId + \"<br>URL: \" + window.location.href + \"<br>UserAgent: \" + userAgent + \"<br>\" + msg + \" in \" + url + \" at line \" + linenumber + \"'</div></div>\");",
"lineNumber": 527,
"lineChange": "removed"
},
{
"line": " + \"ErrorId: \" + errorId + \"<br>URL: \" + padutils.escapeHtml(window.location.href) + \"<br>UserAgent: \" + userAgent + \"<br>\" + msg + \" in \" + url + \" at line \" + linenumber + \"'</div></div>\");",
"lineNumber": 527,
"lineChange": "added"
},
{
"line": "}",
"lineNumber": 528,
"lineChange": "none"
}
]
}
],
"exampleCommitDescriptions": [
"Add unit test.",
"e3db0cd CHANGES.md\n84d1acf Add tests.",
"Update and clean up the tests by using the iframe's load event."
],
"precision": "very-high",
"repoDatasetSize": 1482,
"cwe": [
"CWE-79"
]
}
}
]
}
},
"results": [
{
"ruleId": "php/PT",
"ruleIndex": 0,
"level": "error",
"message": {
"text": "Unsanitized input from an HTTP header flows into file_get_contents, where it is used as a path. This may result in a Path Traversal vulnerability and allow an attacker to read arbitrary files.",
"markdown": "Unsanitized input from {0} {1} into {2}, where it is used as a path. This may result in a Path Traversal vulnerability and allow an attacker to read arbitrary files.",
"arguments": [
"[an HTTP header](0)",
"[flows](1),(2),(3),(4),(5),(6),(7)",
"[file_get_contents](8)"
]
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 309,
"endLine": 309,
"startColumn": 12,
"endColumn": 274
}
}
}
],
"fingerprints": {
"0": "74e0b3c5c5f55e198afe2b2f3265e677cfaaea0c3060460435b4e62578969335",
"1": "80f1517a.464a7316.c3dea7ce.f18a7ecf.20a8e692.39e0148c.480b110d.be170d97.43f154ae.abf264c1.2173882d.abd479c7.20a8e692.c1b6b7bc.b2a0b7cd.58bf5da9"
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 303,
"endLine": 303,
"startColumn": 22,
"endColumn": 53
}
}
}
},
{
"location": {
"id": 1,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 303,
"endLine": 303,
"startColumn": 22,
"endColumn": 53
}
}
}
},
{
"location": {
"id": 2,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 303,
"endLine": 303,
"startColumn": 15,
"endColumn": 60
}
}
}
},
{
"location": {
"id": 3,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 303,
"endLine": 303,
"startColumn": 9,
"endColumn": 11
}
}
}
},
{
"location": {
"id": 4,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 309,
"endLine": 309,
"startColumn": 196,
"endColumn": 198
}
}
}
},
{
"location": {
"id": 5,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 309,
"endLine": 309,
"startColumn": 30,
"endColumn": 198
}
}
}
},
{
"location": {
"id": 6,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 309,
"endLine": 309,
"startColumn": 30,
"endColumn": 212
}
}
}
},
{
"location": {
"id": 7,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 309,
"endLine": 309,
"startColumn": 30,
"endColumn": 228
}
}
}
},
{
"location": {
"id": 8,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 309,
"endLine": 309,
"startColumn": 12,
"endColumn": 274
}
}
}
}
]
}
]
}
],
"properties": {
"priorityScore": 803,
"priorityScoreFactors": [
{
"label": true,
"type": "hotFileSource"
},
{
"label": true,
"type": "fixExamples"
}
]
}
},
{
"ruleId": "php/InsecureRandomData",
"ruleIndex": 2,
"level": "error",
"message": {
"text": "An insecure random number generator is used to create an URL (the random value flows from rand). Consider using CSPRNG functions instead.",
"markdown": "An insecure random number generator is used to create {0} (the random value flows from {1}). Consider using CSPRNG functions instead.",
"arguments": [
"[an URL](0)",
"[rand](1)"
]
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 37,
"endLine": 37,
"startColumn": 155,
"endColumn": 166
}
}
}
],
"fingerprints": {
"0": "5e44ae9973bcb6d745343eec5c8dc1799c1597798eaf9068de5e8b689b5bb1c2",
"1": "703ebb77.464a7316.c3dea7ce.73a3d5be.af50231a.773652eb.a7efae7e.be170d97.703ebb77.464a7316.c3dea7ce.73a3d5be.af50231a.773652eb.a7efae7e.be170d97"
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "Modules/functions.php",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 37,
"endLine": 37,
"startColumn": 155,
"endColumn": 166
}
}