-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsemgrep_output_v1_t.ml
More file actions
2745 lines (2465 loc) · 87.9 KB
/
Copy pathsemgrep_output_v1_t.ml
File metadata and controls
2745 lines (2465 loc) · 87.9 KB
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
(* Auto-generated from "semgrep_output_v1.atd" *)
[@@@ocaml.warning "-27-32-33-35-39"]
(**
Specification of the Semgrep CLI JSON output formats using ATD (see
https://atd.readthedocs.io/en/latest/ for information on ATD).
This file specifies mainly the JSON formats of:
- the output of the [semgrep scan --json] command
- the output of the [semgrep test --json] command
- the messages exchanged with the Semgrep backend by the [semgrep ci]
command
It's also (ab)used to specify the JSON input and output of semgrep-core,
some RPC between pysemgrep and semgrep-core, and a few more internal
things. We should use separate .atd for those different purposes but ATD
does not have a proper module system yet and many types are shared so it is
simpler for now to have everything in one file.
There are other important form of outputs which are not specified here:
- The semgrep metrics sent to https://metrics.semgrep.dev in
semgrep_metrics.atd
- The parsing stats of semgrep-core -parsing_stats -json have its own
Parsing_stats.atd
For the definition of the Semgrep input (the rules), see rule_schema_v2.atd
This file has the _v1 suffix to explicitely represent the version of this
JSON format. If you need to extend this file, please be careful because you
may break consumers of this format (e.g., the Semgrep playground or Semgrep
backend or external users of this JSON). See
https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades
for more information on how to smoothly extend the types in this file.
Any backward incompatible changes should require to upgrade the major
version of Semgrep as this JSON output is part of the "API" of Semgrep (any
incompatible changes to the rule format should also require a major version
upgrade). Hopefully, we will always be backward compatible. However, a few
fields are tagged with \[EXPERIMENTAL\] meaning external users should not
rely on them as those fields may be changed or removed. They are not part
of the "API" of Semgrep.
Again, keep in mind that this file is used both by the CLI to *produce* a
JSON output, and by our backends to *consume* the JSON, including to
consume the JSON produced by old versions of the CLI. As of Nov 2024, our
backend is still supporting as far as Semgrep 1.50.0 released Nov 2023.
(see server/semgrep_app/util/cli_version_support.py in the semgrep-app
repo)
This file is translated in OCaml modules by atdgen. Look for the
corresponding Semgrep_output_v1_\[tj\].ml\[i\] generated files under dune's
_build/ folder. A few types below have the 'deriving show' decorator
because those types are reused in semgrep core data structures and we make
heavy use of 'deriving show' in OCaml to help debug things.
This file is also translated in Python modules by atdpy. For Python, a few
types have the 'dataclass(frozen=True)' decorator so that the class can be
hashed and put in set. Indeed, with 'Frozen=True' the class is immutable
and dataclass can autogenerate a hash function for it.
Finally this file is translated in jsonschema/openapi spec by atdcat, and
in Typescript modules by atdts.
History:
- the types in this file were originally inferred from JSON_report.ml for
use by spacegrep when it was separate from semgrep-core. It's now also
useds in JSON_report.ml (now called Core_json_output.ml)
- it was extended to not only support semgrep-core JSON output but also
(py)semgrep CLI output!
- it was then simplified with the osemgrep migration effort by removing
gradually the semgrep-core JSON output.
- it was extended to support 'semgrep ci' output to type most messages sent
between the Semgrep CLI and the Semgrep backend
- we use this file to specify RPCs between pysemgrep and semgrep-core for
the gradual migration effort of osemgrep
- merged what was in Input_to_core.atd here
*)
(** RFC 3339 format *)
type datetime = ATD_string_wrap.Datetime.t
[@@deriving ord]
type dependency_child = { package: string; version: string } [@@deriving ord]
type dependency_kind =
Direct
(**
we depend directly on the 3rd-party library mentioned in the lockfile
(e.g., use of log4j library and concrete calls to log4j in 1st-party
code). log4j must be declared as a direct dependency in the manifest
file.
*)
| Transitive
(**
we depend indirectly (transitively) on the 3rd-party library (e.g.,
if we use lodash which itself uses internally log4j then lodash is a
Direct dependency and log4j a Transitive one)
alt: Indirect
*)
| Unknown
(**
If there is insufficient information to determine the transitivity,
such as a requirements.txt file without a requirements.in manifest,
we leave it Unknown.
*)
[@@deriving ord, eq, show]
type dependency_path = { nodes: dependency_child list } [@@deriving ord]
(**
both ecosystem and transitivity below have frozen=True so the generated
classes can be hashed and put in sets (see calls to reachable_deps.add() in
semgrep SCA code)
alt: type package_manager
*)
type ecosystem =
Npm
| Pypi
| Gem
| Gomod
| Cargo
| Maven
| Composer
| Nuget
| Pub
| SwiftPM
| Cocoapods
| Mix
(**
Deprecated: Mix is a build system, should use Hex, which is the
ecosystem
*)
| Hex
| Opam
[@@deriving eq, ord, show { with_path = false }]
type fpath = ATD_string_wrap.Fpath.t [@@deriving eq, ord, show]
type found_dependency = {
package: string;
version: string;
ecosystem: ecosystem;
allowed_hashes: (string * string list) list (** ??? *);
resolved_url: string option;
transitivity: dependency_kind;
manifest_path: fpath option
(**
Path to the manifest file that defines the project containing this
dependency. Examples: package.json, nested/folder/pom.xml
*);
lockfile_path: fpath option
(**
Path to the lockfile that contains this dependency. Examples:
package-lock.json, nested/folder/requirements.txt, go.mod. Since 1.87.0
*);
line_number: int option
(**
The line number of the dependency in the lockfile. When combined with
the lockfile_path, this can identify the location of the dependency in
the lockfile.
*);
children: dependency_child list option
(**
If we have dependency relationship information for this dependency,
this field will include the name and version of other found_dependency
items that this dependency requires. These fields must match values in
`package` and `version` of another `found_dependency` in the same set
*);
git_ref: string option
(**
Git ref of the dependency if the dependency comes directly from a git
repo. Examples: refs/heads/main, refs/tags/v1.0.0,
e5c704df4d308690fed696faf4c86453b4d88a95. Since 1.66.0
*)
}
[@@deriving ord]
type lockfile_kind =
PipRequirementsTxt
| PoetryLock
| PipfileLock
| UvLock
| NpmPackageLockJson
| YarnLock
| PnpmLock
| BunLock
| BunBinaryLock (** Bun's deprecated binary bun.lockb format *)
| GemfileLock
| GoModLock
| CargoLock
| MavenDepTree (** Not a real lockfile *)
| GradleLockfile
| ComposerLock
| NugetPackagesLockJson
| PubspecLock
| SwiftPackageResolved (** not a real lockfile *)
| PodfileLock
| MixLock
| ConanLock
| OpamLocked
[@@deriving show { with_path = false }, eq, yojson]
type lockfile = { kind: lockfile_kind; path: fpath } [@@deriving show, eq]
type manifest_kind =
RequirementsIn
(**
A Pip Requirements.in in file, which follows the format of
requirements.txt
https://pip.pypa.io/en/stable/reference/requirements-file-format/
*)
| SetupPy
(**
A setup.py file, which is a Python file that contains the setup
configuration for a Python project.
https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#setup-py
*)
| PackageJson
(**
An NPM package.json manifest file
https://docs.npmjs.com/cli/v10/configuring-npm/package-json
*)
| Gemfile
(**
A Ruby Gemfile manifest https://bundler.io/v2.5/man/gemfile.5.html
*)
| GoModManifest (** go.mod https://go.dev/doc/modules/gomod-ref *)
| CargoToml
(**
cargo.toml - https://doc.rust-lang.org/cargo/reference/manifest.html
*)
| PomXml
(**
A Maven pom.xml manifest file
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
*)
| BuildGradle
(**
A Gradle build.gradle build file
https://docs.gradle.org/current/userguide/build_file_basics.html
*)
| BuildGradleKts
(**
A Gradle build.gradle.kts file, which uses Kotlin instead of Groovy.
*)
| SettingsGradle
(**
A Gradle settings.gradle file
https://docs.gradle.org/current/userguide/settings_file_basics.html.
Multi-project builds are defined by settings.gradle rather than
build.gradle:
https://docs.gradle.org/current/userguide/multi_project_builds.html#multi_project_builds
*)
| ComposerJson
(** composer.json - https://getcomposer.org/doc/04-schema.md *)
| NugetManifestJson
(**
manifest for nuget. Could not find a reference; this may not actually
exist
*)
| PubspecYaml (** pubspec.yaml - https://dart.dev/tools/pub/pubspec *)
| PackageSwift
(**
Package.swift
https://docs.swift.org/package-manager/PackageDescription/PackageDescription.html
*)
| Podfile
(** Podfile - https://guides.cocoapods.org/using/the-podfile.html *)
| MixExs
(**
mix.exs
https://hexdocs.pm/elixir/introduction-to-mix.html#project-compilation
*)
| Pipfile (** Pipfile - https://pipenv.pypa.io/en/latest/pipfile.html *)
| PyprojectToml
(**
pyproject.toml
https://packaging.python.org/en/latest/guides/writing-pyproject-toml/
*)
| ConanFileTxt
(**
conanfile.txt
https://docs.conan.io/2.9/reference/conanfile_txt.html#conanfile-txt
*)
| ConanFilePy
(**
conanfile.py - https://docs.conan.io/2.9/reference/conanfile.html
*)
| Csproj
(**
.csproj - https://docs.microsoft.com/en-us/dotnet/core/tools/csproj
*)
| OpamFile
(**
opam - https://opam.ocaml.org/doc/Manual.html#Package-definitions
*)
| BuildSbt
(** build.sbt - https://www.scala-sbt.org/1.x/docs/Basic-Def.html *)
[@@deriving show { with_path = false }, eq]
type manifest = { kind: manifest_kind; path: fpath } [@@deriving show, eq]
(**
This is used in rules to specify the severity of matches/findings. alt:
could be called rule_severity, or finding_severity.
{v
Error = something wrong that must be fixed
Warning = something wrong that should be fixed
Info = some special condition worth knowing about
Experiment = deprecated: guess what
Inventory = deprecated: was used for the Code Asset Inventory (CAI) project
v}
*)
type match_severity = [
`Error
| `Warning
| `Experiment
| `Inventory
| `Critical
(**
since 1.72.0, meant to replace the cases above where Error -> High,
Warning -> Medium. Critical/Low are the only really new category here
without equivalent before. Experiment and Inventory above should be
removed. Info can be kept.
*)
| `High
| `Medium
| `Low
| `Info
(** generic placeholder for non-risky things (including experiments) *)
]
[@@deriving eq, ord, show]
(**
Note that this type is used in Matching_explanation.ml hence the need for
deriving show below.
*)
type matching_operation =
And
| Or
| Inside
| Anywhere
| XPat of string
(**
XPat for eXtended pattern. Can be a spacegrep pattern, a regexp
pattern, or a proper semgrep pattern. see
semgrep-core/src/core/XPattern.ml
*)
| Negation
| Filter of string
| Taint
| TaintSource
| TaintSink
| TaintSanitizer
| EllipsisAndStmts
| ClassHeaderAndElems
[@@deriving show { with_path = false}]
(** Note that there is no filename here like in 'location' below *)
type position = {
line: int;
col: int;
offset: int
(**
Byte position from the beginning of the file, starts at 0. OCaml code
sets it correctly. Python code sets it to a dummy value (-1). This uses
'~' because pysemgrep < 1.30? was *producing* positions without offset
sometimes, and we want the backend to still *consume* such positions.
Note that pysemgrep 1.97 was still producing dummy positions without an
offset so we might need this ~offset longer than expected?
*)
}
[@@deriving ord, show]
(** a.k.a range *)
type location = { path: fpath; start: position; end_ (*atd end *): position }
[@@deriving ord, show]
(**
The string attached to the location is the actual code from the file. This
can contain sensitive information so be careful!
TODO: the type seems redundant since location already specifies a range.
maybe this saves some effort to the user of this type which do not need to
read the file to get the content.
*)
type loc_and_content = (location * string)
[@@deriving ord]
(**
This type happens to be mostly the same as a loc_and_content for now, but
it's split out because Iago has plans to extend this with more information
*)
type match_intermediate_var = {
location: location;
content: string
(**
Unlike abstract_content, this is the actual text read from the
corresponding source file
*)
}
[@@deriving ord]
(**
Used for a best-effort report to users about what findings they get with
the pro engine that they couldn't with the oss engine.
{v
interproc_taint = requires interprocedural taint
interfile_taint = requires interfile taint
proprietary_language = requires some non-taint pro feature
v}
*)
type pro_feature = {
interproc_taint: bool;
interfile_taint: bool;
proprietary_language: bool
}
[@@deriving ord, show]
(**
Report the engine used to detect each finding. Additionally, if we are able
to infer that the finding could only be detected using the pro engine,
report that the pro engine is required and include basic information about
which feature is required.
{v
OSS = ran with OSS
PRO = ran with PRO, but we didn't infer that OSS couldn't have found this
finding
PRO_REQUIRED = ran with PRO and requires a PRO feature (see pro_feature_used)
v}
Note: OSS and PRO could have clearer names, but for backwards compatibility
we're leaving them as is
*)
type engine_of_finding = [
`OSS
| `PRO
| `PRO_REQUIRED of pro_feature (** Semgrep 1.64.0 or later *)
]
[@@deriving ord, show]
(** escape hatch *)
type raw_json = JSON.Yojson.t [@@deriving eq, ord, show]
(** e.g., "javascript.security.do-not-use-eval" *)
type rule_id = Rule_ID.t
[@@deriving show, eq, ord]
type sbom_kind =
CycloneDXJson (** cyclonedx json - https://cyclonedx.org/docs/1.4/json/ *)
[@@deriving show { with_path = false }, eq]
type sbom = {
kind: sbom_kind;
is_ephemeral: bool
(**
whether or not the SBOM is produced ephemerally, i.e. is not checked in
to version control. if true, references in resolved dependencies will
not point to the SBOM itself.
*);
path: fpath
}
[@@deriving show, eq]
type sca_pattern = {
ecosystem: ecosystem;
package: string;
semver_range: string
}
[@@deriving ord]
type dependency_match = {
dependency_pattern: sca_pattern;
found_dependency: found_dependency;
lockfile: fpath;
dependency_paths: dependency_path list option
(**
All known dependency paths by which the matched (transitive) dependency
was introduced into the project. Each path is ordered from the direct
dependency that introduced it (node 0) to the matched (transitive)
dependency (last node). Computed locally from the resolved dependency
graph at scan time; only populated when dependency-graph
(path-to-transitivity) resolution ran for the ecosystem. Empty/absent
for direct dependencies or ecosystems without graph resolution. The
number of paths per match is capped. EXPERIMENTAL since 1.166.0
*)
}
[@@deriving ord]
type sha1 = ATD_string_wrap.Sha1.t [@@deriving ord]
(** part of cli_match_extra *)
type historical_info = {
git_commit: sha1
(**
Git commit at which the finding is present. Used by "historical" scans,
which scan non-HEAD commits in the git history. Relevant for finding,
e.g., secrets which are buried in the git history which we wouldn't
find at HEAD
*);
git_blob: sha1 option
(**
Git blob at which the finding is present. Sent in addition to the
commit since some SCMs have permalinks which use the blob sha, so this
information is useful when generating links back to the SCM.
*);
git_commit_timestamp: datetime
}
[@@deriving ord]
type svalue_value = {
svalue_start: position option;
svalue_end: position option;
svalue_abstract_content: string (** value? *)
}
[@@deriving ord]
type metavar_value = {
start: position
(**
for certain metavariable like $...ARGS, 'end' may be equal to 'start'
to represent an empty metavariable value. The rest of the Python code
(message metavariable substitution and autofix) works without change
for empty ranges (when end = start).
*);
end_ (*atd end *): position;
abstract_content: string (** value? *);
propagated_value: svalue_value option
}
[@@deriving ord]
(**
Name/value map of the matched metavariables. The leading '$' must be
included in the metavariable name.
*)
type metavars = (string * metavar_value) list
[@@deriving ord]
type transitive_undetermined = { explanation: string option }
[@@deriving ord]
type transitive_unreachable = {
analyzed_packages: found_dependency list
(**
We didn't find any findings in all the 3rd party libraries that are
using the 3rd party vulnerable library. This is a "proof of work".
*);
explanation: string option
(** some extra explanation that the user can understand *)
}
[@@deriving ord]
(**
This type is used by postprocessors for secrets to report back the validity
of a finding. No_validator is currently also used when no validation has
yet occurred, which if that becomes confusing we could adjust that, by
adding another state.
*)
type validation_state = [
`Confirmed_valid | `Confirmed_invalid | `Validation_error | `No_validator
]
[@@deriving eq, ord, show]
type dependency_source =
ManifestOnly of manifest
| LockfileOnly of lockfile
| ManifestLockfile of (manifest * lockfile)
| MultiLockfile of dependency_source list
(**
The dependency_source should be LockfileOnly or ManifestLockfile, but
not ManifestOnlyDependencySource. Right now this variant is only used
by pysemgrep; it is deconstructed in multiple LockfileXxx when
calling the dynamic resolver. Note that this variant introduces a
series of problems in the Python code because atdpy generates a
List\[DependencySource\] and List are not hashable in Python. We had
to define a special hash function for Subproject to avoid hashing the
dependency_source.
*)
| AuxillarySBOM of (sbom * dependency_source)
(**
An SBOM containing dependency information that is not part of the
dependency source files directly interpreted by the package manager.
This is connected to a standard dependency source. The attached
dependency source should not be another AuxillarySBOM. Ideally we
would restructure this type to encode this requirement.
*)
[@@deriving show]
type match_call_trace =
CliLoc of loc_and_content
| CliCall
of (loc_and_content * match_intermediate_var list * match_call_trace)
[@@deriving ord]
type match_dataflow_trace = {
taint_source: match_call_trace option;
intermediate_vars: match_intermediate_var list option
(**
Intermediate variables which are involved in the dataflow. This
explains how the taint flows from the source to the sink.
*);
taint_sink: match_call_trace option
}
[@@deriving ord]
type cli_match = {
check_id: rule_id;
path: fpath;
start: position;
end_ (*atd end *): position;
extra: cli_match_extra
}
and cli_match_extra = {
metavars: metavars option
(**
Since 1.98.0, you need to be logged in to get this field. note: we also
need ?metavars because dependency_aware code
*);
message: string
(**
Those fields are derived from the rule but the metavariables they
contain have been expanded to their concrete value.
*);
fix: string option
(**
If present, semgrep was able to compute a string that should be
inserted in place of the text in the matched range in order to fix the
finding. Note that this is the result of applying both the fix: or
fix_regex: in a rule.
*);
fixed_lines: string list option;
metadata: raw_json (** fields coming from the rule *);
severity: match_severity;
fingerprint: string
(** Since 1.98.0, you need to be logged in to get those fields *);
lines: string;
is_ignored: bool option (** for nosemgrep *);
sca_info: sca_match option
(** EXPERIMENTAL: added by dependency_aware code *);
validation_state: validation_state option
(**
EXPERIMENTAL: If present indicates the status of postprocessor
validation. This field not being present should be equivalent to
No_validator. Added in semgrep 1.37.0
*);
historical_info: historical_info option
(**
EXPERIMENTAL: added by secrets post-processing & historical scanning
code Since 1.60.0.
*);
dataflow_trace: match_dataflow_trace option
(**
EXPERIMENTAL: For now, present only for taint findings. May be extended
to others later on.
*);
engine_kind: engine_of_finding option;
extra_extra: raw_json option
(** EXPERIMENTAL: see core_match_extra.extra_extra *)
}
(** part of cli_match_extra, core_match_extra, and finding *)
and sca_match = {
reachability_rule: bool
(**
does the rule has a pattern part; otherwise it's a "parity" or
"upgrade-only" rule.
*);
sca_finding_schema: int;
dependency_match: dependency_match;
reachable: bool;
kind: sca_match_kind option (** EXPERIMENTAL since 1.108.0 *)
}
(**
Note that in addition to "reachable" there are also the notions of
"vulnerable" and "exploitable".
*)
and sca_match_kind =
LockfileOnlyMatch of dependency_kind
(**
This is used for "parity" or "upgrade-only" rules. transitivity
indicates whether the match is for a direct or transitive usage of
the dependency; for a dependency that is both direct and transitive
two findings should be generated.
*)
| DirectReachable
(**
found the pattern-part of the SCA rule in 1st-party code (reachable
as originally defined by Semgrep Inc.) the match location will be in
some target code.
*)
| TransitiveReachable of transitive_reachable
(**
found the pattern-part of the SCA rule in third-party code and
ultimately found a path from 1st party code to this vulnerable
third-party code. The goal of transitive reachability analysis is to
change some Undetermined or (LockfileOnlyMatch Transitive) into
TransitiveReachable or TransitiveUnreachable
*)
| TransitiveUnreachable of transitive_unreachable
(**
This is a "positive" finding in the sense that semgrep was able to
prove that the transitive finding is "safe" and can be ignored
because either there is no call to the pattern-part of the SCA rule
in 3rd party code, or if there is it's in third-party code that is
not accessed from the 1st-party code (e.g., via callgraph analysis)
Note that there is no need for DirectUnreachable because semgrep
would never generate such a finding. We have TransitiveUnreachable
because semgrep first generates some Undetermined that we then retag
as DirectUnreachable.
*)
| TransitiveUndetermined of transitive_undetermined
(**
could not decide because of the engine limitations (e.g., found the
use of a vulnerable library in the lockfile but could not find the
pattern in first party code and could not access third-party code for
further investigation (similar to (LockfileOnlyMatch Transitive))
*)
[@@deriving ord]
and transitive_reachable = {
matches: (found_dependency * cli_match list) list
(**
The matches we found in 3rd party libraries. Ideally the location in
cli_match are relative to the root of the project so one can display
matches as package\@/path/to/finding.py
*);
callgraph_reachable: bool option
(**
LATER: add callgraph information so one can see the path from 1st party
code to the vulnerable intermediate 3rd party function. This is set to
None for now.
*);
explanation: string option
(** some extra explanation that the user can understand *)
}
(**
See the corresponding comment in cli_match_extra for more information about
the fields below.
*)
type core_match_extra = {
metavars: metavars;
engine_kind: engine_of_finding;
is_ignored: bool;
message: string option
(**
These fields generally come from the rule, but may be set here if
they're being overriden for that particular finding. This would
currently occur for rule with a validator for secrets, depending on
what the validator might match, but could be expanded in the future.
*);
metadata: raw_json option;
severity: match_severity option;
fix: string option;
dataflow_trace: match_dataflow_trace option;
sca_match: sca_match option;
validation_state: validation_state option;
historical_info: historical_info option;
extra_extra: raw_json option
(**
Escape hatch to pass untyped info from semgrep-core to the semgrep
output. Useful for quick experiments, especially when combined with
semgrep --core-opts flag.
*)
}
type core_match = {
check_id: rule_id;
path: fpath;
start: position;
end_ (*atd end *): position;
extra: core_match_extra
}
(**
For any "extra" information that we cannot fit at the node itself. This is
useful for kind-specific information, which we cannot put in the operation
itself without giving up our ability to derive `show` (needed for
`matching_operation` below).
*)
type matching_explanation_extra = {
before_negation_matches: core_match list option
(**
Only present in And kind. This information is useful for determining
the input matches to the first Negation node.
*);
before_filter_matches: core_match list option
(**
Only present in nodes which have children Filter nodes. This
information is useful for determining the input matches to the first
Filter node, as there is otherwise no way of obtaining the
post-intersection matches in an And node, for instance
*)
}
(** EXPERIMENTAL *)
type matching_explanation = {
op: matching_operation;
children: matching_explanation list;
matches: core_match list
(** result matches at this node (can be empty when we reach a nomatch) *);
loc: location
(**
location in the rule file! not target file. This tries to delimit the
part of the rule relevant to the current operation (e.g., the position
of the 'patterns:' token in the rule for the And operation).
*);
extra: matching_explanation_extra option (** NEW: since v1.79 *)
}
(**
These ratios are numbers in \[0, 1\], and we would hope that both
'time_ratio' and 'count_ratio' are very close to 0. In bad cases, we may
see the 'count_ratio' being close to 0 while the 'time_ratio' is above 0.5,
meaning that a small number of very slow files/etc represent a large amount
of the total processing time. EXPERIMENTAL
*)
type very_slow_stats = {
time_ratio: float (** Ratio "sum of very slow time" / "total time" *);
count_ratio: float (** Ratio "very slow count" / "total count" *)
}
(** e.g., '1.1.0' *)
type version = string [@@deriving show]
type uuid = ATD_string_wrap.Uuidm.t [@@deriving ord]
type uri = ATD_string_wrap.Uri.t [@@deriving ord]
(** A symbol is a FQN. *)
type symbol = { fqn: string list }
[@@deriving show]
(**
We store the location of the usage, because we may want to be able to know
how many uses of the symbol there are, and where.
*)
type symbol_usage = { symbol: symbol; locs: location list }
[@@deriving show]
type symbol_analysis = symbol_usage list [@@deriving show]
type upload_subproject_symbol_analysis_params = {
token: string;
scan_id: int;
manifest: fpath option;
lockfile: fpath option;
symbol_analysis: symbol_analysis
}
type unresolved_reason =
UnresolvedFailed (** Resolution was attempted, but was unsuccessful. *)
| UnresolvedSkipped
(**
Resolution was skipped because the dependency source was not relevant
to the scanned targets.
*)
| UnresolvedUnsupported
(**
Resolution was skipped because the dependency source is not
supported.
*)
| UnresolvedDisabled
(**
Resolution was not attempted because a required feature (such as
local builds) was disabled.
*)
(**
A subproject defined by some kind of manifest file (e.g., pyproject.toml,
package.json, ...). This may be at the root of the repo being scanned or
may be some other folder. Used as the unit of analysis for supply chain.
*)
type subproject = {
root_dir: fpath;
ecosystem: ecosystem option
(**
This is used to match code files with subprojects. It is necessary to
have it here, even before a subproject's dependencies are resolved, in
order to decide whether a certain subproject must be resolved given the
changes included in a certain diff scan. It can be None if this
subproject is for a package manager whose ecosystem is not yet
supported (i.e. one that is identified only for tracking purposes)
*);
dependency_source: dependency_source
(**
The dependency source is how we resolved the dependencies. This might
be a lockfile/manifest pair (the only current one), but in the future
it might also be dynamic resolution based on a manifest, an SBOM, or
something else
*)
}
[@@deriving show]
(**
JSON names are to maintain backwards compatibility with the python enum it
is replacing. The P prefix (for parser) is to avoid ambiguity with similar
construtor names in the manifest and ecosystem types.
*)
type sca_parser_name =
PGemfile_lock | PGo_mod | PGo_sum | PGradle_lockfile | PGradle_build
| PJsondoc | PPipfile | PPnpm_lock | PPoetry_lock | PPyproject_toml
| PRequirements | PYarn_1 | PYarn_2 | PPomtree | PCargo_parser
| PComposer_lock | PPubspec_lock | PPackage_swift | PPodfile_lock
| PPackage_resolved | PMix_lock
[@@deriving show]
type resource_inaccessible = {
command: string;
registry_url: string option
(**
we attempt to parse out the actual registry URL that we tried to access
*);
message: string
(** and just include the entire error message too, just in case *)
}
[@@deriving show]
type resolution_cmd_failed = { command: string; message: string }
[@@deriving show]
type resolution_error_kind =
UnsupportedManifest
| MissingRequirement of string
| ResolutionCmdFailed of resolution_cmd_failed
| ParseDependenciesFailed of string
(**
when we produce some dependency list in lockfileless scanning (by
talking to the package manager) but fail to parse it correctly
*)
| ScaParseError of sca_parser_name
(**
a lockfile parser failed since semgrep 1.109.0 (to replace
dependency_parser_error)
*)
| ResourceInaccessible of resource_inaccessible
(**
unable to access private registry, likely due to missing credentials
*)
[@@deriving show]
(** used only from pysemgrep for now *)
type sca_resolution_error = {
type_: resolution_error_kind;
dependency_source_file: fpath
}
type dependency_parser_error = {
path: fpath;
parser: sca_parser_name;
reason: string;
line: int option
(**
Not using `position` because this type must be backwards compatible
with the python class it is replacing.
*);
col: int option;
text: string option
}
type sca_error =
SCAParse of dependency_parser_error
| SCAResol of sca_resolution_error
type unresolved_subproject = {
info: subproject;
reason: unresolved_reason;
errors: sca_error list
(** this is set only when the reason is UnresolvedFailed *)