-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrule_schema_v1.yaml
1203 lines (1199 loc) · 33.4 KB
/
rule_schema_v1.yaml
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
# Specification of the Semgrep rule YAML syntax using JSON schema.
#
# Note that even if most Semgrep users use YAML to write a rule, and not JSON,
# we still use a JSON tool (jsonschema) to specify the rule schema because
# YAML is a superset of JSON and can be mechanically translated into JSON;
# there is no yamlschema (see https://json-schema-everywhere.github.io/yaml).
# To add even more confusion, a jsonschema can actually be specified using
# YAML (like in in this file), and so one can use YAML syntax to specify the
# JSON schema of files actually written in YAML (hmmm).
$id: https://raw.githubusercontent.com/returntocorp/semgrep-interfaces/main/rule_schema_v1.yaml
$schema: http://json-schema.org/draft-07/schema#
#!!If you modify this file, update the submodules in semgrep and semgrep-app!!
#!!If you add new syntax to this file, you probably need to add some
# EXPERIMENTAL comment before!!
$defs:
# EXPERIMENTAL
validator:
properties:
http:
properties:
request:
$ref: "#/$defs/http-request-content"
response:
$ref: "#/$defs/http-response-content"
required: [ request, response ]
aws:
properties:
request:
$ref: "#/$defs/aws-request-content"
response:
$ref: "#/$defs/http-response-content"
required: [ request, response ]
# An individual validator shall be exactly one 'kind' of validator.
oneOf:
- required: [ http ]
- required: [ aws ]
analyzer:
title: Analyzer to use
oneOf:
- const: entropy
- const: entropy_v2
- const: redos
- type: object
properties:
kind:
const: entropy
required:
- kind
additionalProperties: false
- type: object
properties:
kind:
const: entropy_v2
mode:
oneOf:
- const: lax
- const: strict
- const: default
required:
- kind
additionalProperties: false
- type: object
properties:
kind:
const: redos
required:
- kind
additionalProperties: false
# EXPERIMENTAL
aws-request-content:
properties:
access_key_id:
type: string
secret_access_key:
type: string
region:
type: string
session_token:
type: string
required: [ access_key_id, secret_access_key, region ]
# EXPERIMENTAL
http-request-content:
properties:
url:
type: string
method:
type: string
headers:
type: object
body:
type: string
auth:
type: object
# EXPERIMENTAL
http-response-content:
type: array
items:
$ref: "#/$defs/http-response-item"
# EXPERIMENTAL
http-response-item:
properties:
match:
$ref: "#/$defs/http-response-match"
result:
properties:
validity:
enum: [ valid, invalid ]
# EXPERIMENTAL
http-response-match:
properties:
status-code:
type: integer
headers:
type: array
items:
properties:
name:
type: string
value:
type: string
content:
type: object
properties:
# TODO(cooper): re-use languages sub-enum?
language:
type: string
$ref: "#/$defs/general-pattern-content"
# EXPERIMENTAL
new-source-pattern:
$ref: "#/$defs/new-pattern"
properties:
requires:
type: string
label:
type: string
new-sink-pattern:
$ref: "#/$defs/new-pattern"
properties:
requires:
type: string
new-sanitizer-pattern:
$ref: "#/$defs/new-pattern"
properties:
not-conflicting:
type: string
new-propagator-pattern:
$ref: "#/$defs/new-pattern"
required: [ from, to ]
properties:
from:
type: string
to:
type: string
new-taint-content:
title: "Return finding using taint, given sources and sinks"
type: object
required:
- sources
- sinks
properties:
sources:
type: array
minItems: 1
items:
$ref: "#/$defs/new-source-pattern"
sinks:
type: array
minItems: 1
items:
$ref: "#/$defs/new-sink-pattern"
propagators:
type: array
minItems: 1
items:
$ref: "#/$defs/new-propagator-pattern"
sanitizers:
type: array
minItems: 1
items:
$ref: "#/$defs/new-sanitizer-pattern"
new-pattern:
title: "Return finding where code matches against the following pattern"
oneOf:
- type: string
- type: object
oneOf:
- required: [ pattern ]
- required: [ regex ]
- required: [ all ]
- required: [ any ]
- required: [ not ]
- required: [ inside ]
- required: [ anywhere ]
- required: [ taint ]
properties:
pattern:
type: string
regex:
type: string
all:
type: array
minItems: 1
items:
$ref: "#/$defs/new-pattern"
any:
type: array
minItems: 1
items:
$ref: "#/$defs/new-pattern"
not:
$ref: "#/$defs/new-pattern"
inside:
$ref: "#/$defs/new-pattern"
anywhere:
$ref: "#/$defs/new-pattern"
where:
type: array
items:
oneOf:
- required: [ focus ]
properties:
focus:
oneOf:
- type: string
- type: array
items:
type: string
- required: [ comparison ]
properties:
comparison:
type: string
base:
title: Integer base to parse metavariable contents as
type: integer
strip:
title: Whether to strip quotes from compared metavariables
type: boolean
- required: [ metavariable ]
$ref: "#/$defs/new-pattern"
properties:
metavariable:
type: string
- required: [ metavariable, type ]
properties:
metavariable:
type: string
type:
type: string
- required: [ metavariable, types ]
properties:
metavariable:
type: string
types:
type: array
items:
type: string
- required: [ metavariable, analyzer ]
properties:
metavariable:
type: string
analyzer:
$ref: "#/$defs/analyzer"
general-pattern-content:
title: "Return finding where code matches against the following pattern"
oneOf:
- type: string
# This is scuffed, but it seems that `allOf` does not short circuit.
# This schema can potentially run on things which are not objects
# (such as lists), and if that happens, the validator will crash when
# it checks the keys of the object.
# I would normally just use `allOf`, but since it doensn't short circuit,
# I had to instead make it this weird `if-then-else` thing to properly
# skip the keys check on a non-object.
- if:
type: object
then:
oneOf:
- required: [ pattern ]
- required: [ pattern-regex ]
- required: [ patterns ]
- required: [ pattern-either ]
- required: [ pattern-not ]
- required: [ pattern-inside ]
- required: [ semgrep-internal-pattern-anywhere ]
- required: [ pattern-not-inside ]
properties:
pattern:
type: string
pattern-regex:
type: string
patterns:
$ref: "#/$defs/patterns-content"
pattern-either:
$ref: "#/$defs/pattern-either-content"
pattern-not:
$ref: "#/$defs/general-pattern-content"
pattern-inside:
$ref: "#/$defs/general-pattern-content"
semgrep-internal-pattern-anywhere:
$ref: "#/$defs/general-pattern-content"
pattern-not-inside:
$ref: "#/$defs/general-pattern-content"
else:
type: object
patterns-content:
type: array
title: "Return finding where all of the nested conditions are true"
items:
anyOf:
- $ref: "#/$defs/patterns"
- $ref: "#/$defs/pattern-either"
- $ref: "#/$defs/focus-metavariable"
- $ref: "#/$defs/pattern-inside"
- $ref: "#/$defs/semgrep-internal-pattern-anywhere"
- $ref: "#/$defs/pattern-not-inside"
- $ref: "#/$defs/pattern-not"
- $ref: "#/$defs/pattern"
- $ref: "#/$defs/pattern-regex"
- $ref: "#/$defs/pattern-not-regex"
- $ref: "#/$defs/metavariable-analysis"
- $ref: "#/$defs/metavariable-regex"
- $ref: "#/$defs/metavariable-pattern"
- $ref: "#/$defs/metavariable-type"
- $ref: "#/$defs/semgrep-internal-metavariable-name"
- $ref: "#/$defs/metavariable-comparison"
- $ref: "#/$defs/pattern-where-python"
pattern-either-content:
type: array
title: "Return finding where any of the nested conditions are true"
items:
anyOf:
- $ref: "#/$defs/patterns"
- $ref: "#/$defs/pattern-either"
- $ref: "#/$defs/pattern-inside"
- $ref: "#/$defs/semgrep-internal-pattern-anywhere"
- $ref: "#/$defs/pattern"
- $ref: "#/$defs/pattern-regex"
taint-content:
type: array
items:
anyOf:
- type: object
properties:
pattern:
title: Return finding where Semgrep pattern matches exactly
type: string
pattern-regex:
title: Return finding where regular expression matches exactly
type: string
patterns:
$ref: "#/$defs/patterns-content"
pattern-either:
$ref: "#/$defs/pattern-either-content"
oneOf:
- required:
- pattern
not:
anyOf:
- required:
- patterns
- required:
- pattern-either
- required:
- pattern-regex
- required:
- patterns
not:
anyOf:
- required:
- pattern
- required:
- pattern-either
- required:
- pattern-regex
- required:
- pattern-either
not:
anyOf:
- required:
- pattern
- required:
- patterns
- required:
- pattern-regex
- required:
- pattern-regex
not:
anyOf:
- required:
- pattern
- required:
- patterns
- required:
- pattern-either
# EXPERIMENTAL
r2c-internal-project-depends-on-content:
type: object
title: "One or more dependencies that the project contains in a lock file"
properties:
namespace:
type: string
package:
type: string
version:
type: string
depends-on-either:
type: array
properties:
namespace:
type: string
package:
type: string
version:
type: string
additionalProperties: false
required:
- namespace
- package
- version
oneOf:
- required:
- namespace
- package
- version
not:
required:
- depends-on-either
- required:
- depends-on-either
not:
anyOf:
- required:
- namespace
- required:
- package
- required:
- version
# EXPERIMENTAL
join-content:
type: object
title: "Join one or more rules together based on metavariable contents"
properties:
refs:
type: array
items:
type: object
properties:
rule:
type: string
renames:
type: array
items:
type: object
properties:
from:
type: string
to:
type: string
as:
type: string
additionalProperties: false
rules:
type: array
items:
type: object
required:
- id
- languages
oneOf:
- required:
- pattern
- required:
- patterns
- required:
- pattern-sources
- pattern-sinks
properties:
id:
$ref: "#/$defs/id"
languages:
$ref: "#/$defs/languages"
pattern:
type: string
patterns:
$ref: "#/$defs/patterns-content"
mode:
enum:
- search
- taint
pattern-sources:
$ref: "#/$defs/taint-content"
pattern-propagators:
$ref: "#/$defs/taint-content"
pattern-sinks:
$ref: "#/$defs/taint-content"
pattern-sanitizers:
$ref: "#/$defs/taint-content"
additionalProperties: false
on:
type: array
items:
type: string
additionalProperties: false
additionalProperties: false
# This a generic version of metavariable-regex and metavariable-pattern.
# It is meant to allow a variety of built-in analyzers, each with a
# name and its own options. For example, this is used for the entropy
# analyzer.
metavariable-analysis:
type: object
properties:
metavariable-analysis:
type: object
title: Inspect a metavariable with a given analyzer
properties:
analyzer:
$ref: "#/$defs/analyzer"
metavariable:
type: string
title: Metavariable to analyze
required:
- analyzer
- metavariable
additionalProperties: false
required:
- metavariable-analysis
additionalProperties: false
metavariable-regex:
type: object
properties:
metavariable-regex:
type: object
title: Search metavariable value with RegEx
properties:
metavariable:
type: string
title: Metavariable to search
regex:
type: string
title: PCRE regular expression
constant-propagation:
type: boolean
required:
- metavariable
- regex
additionalProperties: false
required:
- metavariable-regex
additionalProperties: false
metavariable-pattern:
type: object
properties:
metavariable-pattern:
type: object
title: Match metavariable value with a pattern formula
properties:
metavariable:
type: string
title: Metavariable to match
language:
type: string
pattern:
title: Return finding where Semgrep pattern matches exactly
type: string
pattern-regex:
title: Return finding where regular expression matches exactly
type: string
patterns:
$ref: "#/$defs/patterns-content"
pattern-either:
$ref: "#/$defs/pattern-either-content"
required:
- metavariable
oneOf:
- required:
- pattern
not:
anyOf:
- required:
- patterns
- required:
- pattern-either
- required:
- pattern-regex
- required:
- patterns
not:
anyOf:
- required:
- pattern
- required:
- pattern-either
- required:
- pattern-regex
- required:
- pattern-either
not:
anyOf:
- required:
- pattern
- required:
- patterns
- required:
- pattern-regex
- required:
- pattern-regex
not:
anyOf:
- required:
- pattern
- required:
- patterns
- required:
- pattern-either
additionalProperties: false
required:
- metavariable-pattern
additionalProperties: false
metavariable-type:
type: object
properties:
metavariable-type:
type: object
title: Filter for metavariables with a certain type
properties:
metavariable:
type: string
title: Metavariable to match
type:
title: Type expression
type: string
types:
title: Type expressions
type: array
items:
type: string
language:
type: string
oneOf:
- required:
- type
- required:
- types
additionalProperties: false
required:
- metavariable-type
additionalProperties: false
semgrep-internal-metavariable-name:
type: object
properties:
semgrep-internal-metavariable-name:
type: object
title: Filter for metavariables with a certain kind
properties:
metavariable:
type: string
title: Metavariable to match
kind:
title: Kind keyword
type: string
module:
title: A module name
type: string
modules:
title: A list of module names
type: array
items:
type: string
required:
- metavariable
anyOf:
- required:
- kind
- oneOf:
- required:
- module
- required:
- modules
additionalProperties: false
required:
- semgrep-internal-metavariable-name
additionalProperties: false
metavariable-comparison:
type: object
properties:
metavariable-comparison:
type: object
title: Compare metavariables with other metavariables or literals using constant propagation
properties:
metavariable:
type: string
title: Metavariable to compare
comparison:
type: string
title: Comparison expression
strip:
type: boolean
base:
type: integer
required:
- comparison
additionalProperties: false
required:
- metavariable-comparison
additionalProperties: false
pattern:
type: object
properties:
pattern:
title: Return finding where Semgrep pattern matches exactly
type: string
required:
- pattern
additionalProperties: false
pattern-regex:
type: object
properties:
pattern-regex:
title: Return finding where regular expression matches
type: string
required:
- pattern-regex
additionalProperties: false
pattern-not-regex:
type: object
properties:
pattern-not-regex:
title: Do not return finding where regular expression matches
type: string
required:
- pattern-not-regex
additionalProperties: false
patterns:
type: object
properties:
patterns:
title: Return finding where all of the nested conditions are true
$ref: "#/$defs/patterns-content"
required:
- patterns
additionalProperties: false
pattern-either:
type: object
properties:
pattern-either:
title: Return finding where any of the nested conditions are true
$ref: "#/$defs/pattern-either-content"
required:
- pattern-either
additionalProperties: false
focus-metavariable:
type: object
properties:
focus-metavariable:
title: Focus on what a given metavariable is matching
items:
OneOf:
- string
- array
required:
- focus-metavariable
additionalProperties: false
pattern-inside:
type: object
properties:
pattern-inside:
title: Return findings only from within snippets Semgrep pattern matches
$ref: "#/$defs/general-pattern-content"
required:
- pattern-inside
additionalProperties: false
# EXPERIMENTAL
semgrep-internal-pattern-anywhere:
type: object
properties:
semgrep-internal-pattern-anywhere:
title: >-
Marks this subpattern such that at a containing `patterns` or other
form of conjunction the range is not considered; subpattern matches
are instead combined solely on the basis of metavariables, without
respect to range, and the range of the matching subpattern is
discarded wholly.
$ref: "#/$defs/general-pattern-content"
required:
- semgrep-internal-pattern-anywhere
additionalProperties: false
pattern-not-inside:
type: object
properties:
pattern-not-inside:
title: Do not return findings from within snippets Semgrep pattern matches
$ref: "#/$defs/general-pattern-content"
required:
- pattern-not-inside
additionalProperties: false
pattern-not:
type: object
properties:
pattern-not:
title: Do not return finding where Semgrep pattern matches exactly
$ref: "#/$defs/general-pattern-content"
required:
- pattern-not
additionalProperties: false
# DEPRECATED
pattern-where-python:
type: object
properties:
pattern-where-python:
title: Return finding where Python expression returns true
type: string
required:
- pattern-where-python
additionalProperties: false
path-array:
type: array
items:
type: string
id:
title: Rule ID to attach to findings
type: string
pattern: "^[a-zA-Z0-9._-]*$"
# coupling: if you modify this, you first need to modify lang.json in the semgrep-langs repository
languages:
title: Languages this pattern should run on
type: array
items:
anyOf:
- type: string
- enum:
- apex
- bash
- sh
- c
- clojure
- cpp
- c++
- csharp
- c#
- dart
- dockerfile
- docker
- ex
- elixir
- generic
- go
- golang
- hack
- html
- java
- js
- javascript
- json
- jsonnet
- julia
- kt
- kotlin
- lisp
- lua
- ocaml
- php
- python2
- python3
- py
- python
- r
- regex
- none
- ruby
- rust
- scala
- scheme
- solidity
- sol
- swift
- tf
- hcl
- terraform
- ts
- typescript
- vue
- yaml
required:
- rules
properties:
rules:
type: array
items:
type: object
properties:
id:
$ref: "#/$defs/id"
min-version:
title: Earliest Semgrep version supporting this rule
type: string
max-version:
title: Last Semgrep version supporting this rule
type: string
version:
title: Version of rule
type: string
message:
title: Description to attach to findings
type: string
mode:
default: search
enum:
- search
- taint
# EXPERIMENTAL
- join
- extract
languages:
$ref: "#/$defs/languages"
paths:
title: Path globs this pattern should run on
type: object
properties:
include:
$ref: "#/$defs/path-array"
exclude:
$ref: "#/$defs/path-array"
additionalProperties: false
severity:
title: Severity to report alongside this finding
enum:
- ERROR
- WARNING
- INFO
# EXPERIMENTAL
- INVENTORY
- EXPERIMENT
# since 1.72.0
- CRITICAL
- HIGH
- MEDIUM
- LOW
pattern-sinks:
$ref: "#/$defs/taint-content"
pattern-sources:
$ref: "#/$defs/taint-content"
pattern-sanitizers:
$ref: "#/$defs/taint-content"
# EXPERIMENTAL
pattern-propagators:
$ref: "#/$defs/taint-content"
taint:
$ref: "#/$defs/new-taint-content"
join:
$ref: "#/$defs/join-content"
# EXPERIMENTAL
validators:
type: array
minItems: 1
items:
$ref: "#/$defs/validator"
fix:
title: Replacement text to fix matched code. Can use matched metavariables.
type: string
fix-regex:
type: object
title: Replacement regex to fix matched code.
properties:
count:
title: Replace up to this many regex matches
type: integer
regex:
title: Regular expression to find in matched code
type: string
replacement:
title: Code to replace the regular expression match with. Can use capture groups.
type: string
required:
- regex
- replacement
additionalProperties: false
metadata:
title: Arbitrary structured data for your own reference
type: object
options:
title: Options object to enable/disable certain matching features in semgrep-core
type: object
pattern:
title: Return finding where Semgrep pattern matches exactly
type: string
pattern-regex:
title: Return finding where regular expression matches exactly
type: string
patterns:
$ref: "#/$defs/patterns-content"
pattern-either:
$ref: "#/$defs/pattern-either-content"
# EXPERIMENTAL
r2c-internal-project-depends-on:
$ref: "#/$defs/r2c-internal-project-depends-on-content"
# EXPERIMENTAL
match:
$ref: "#/$defs/new-pattern"