-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48fe559
commit 7990c86
Showing
11 changed files
with
155 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Dependency | ||
## Information | ||
Name: {{vulnerable-dependency.dependency}} | ||
Version: {{vulnerable-dependency.mvn/version}} | ||
|
||
## Vulnerabilities | ||
{% for identifier in identifiers %} | ||
- {{identifier.value}} | ||
{% endfor %} | ||
|
||
## Location | ||
{% if vulnerable-dependency.parents|empty? %} | ||
Impossible to find dependency in tree. | ||
It could be a jar inside some project. | ||
|
||
{% else %} | ||
{{vulnerable-dependency.parents|build-tree}} | ||
{% endif %} | ||
# Fix suggestion | ||
```clojure | ||
{{vulnerable-dependency.remediate-suggestion|safe}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
(ns clj-watson.controller.output | ||
(:require | ||
[cheshire.core :as json] | ||
[clj-watson.logic.stdout :as logic.stdout] | ||
[clj-watson.logic.sarif :as logic.sarif] | ||
[clj-watson.logic.template :as logic.template] | ||
[clojure.java.io :as io] | ||
[clojure.pprint :as pprint])) | ||
|
||
(defmulti ^:private generate* (fn [_ kind] (keyword kind))) | ||
(defmulti ^:private generate* (fn [_ _ kind] (keyword kind))) | ||
|
||
(defmethod ^:private generate* :stdout-simple [dependencies _] | ||
(defmethod ^:private generate* :stdout-simple [dependencies & _] | ||
(let [template (-> "simple-report.mustache" io/resource slurp)] | ||
(println (logic.stdout/generate dependencies template)))) | ||
(println (logic.template/generate {:vulnerable-dependencies dependencies} template)))) | ||
|
||
(defmethod ^:private generate* :stdout [dependencies _] | ||
(defmethod ^:private generate* :stdout [dependencies & _] | ||
(let [template (-> "full-report.mustache" io/resource slurp)] | ||
(println (logic.stdout/generate dependencies template)))) | ||
(println (logic.template/generate {:vulnerable-dependencies dependencies} template)))) | ||
|
||
(defmethod ^:private generate* :json [dependencies _] | ||
(defmethod ^:private generate* :json [dependencies & _] | ||
(-> dependencies json/generate-string pprint/pprint)) | ||
|
||
(defmethod ^:private generate* :edn [dependencies _] | ||
(defmethod ^:private generate* :edn [dependencies & _] | ||
(pprint/pprint dependencies)) | ||
|
||
(defn generate [dependencies kind] | ||
(generate* dependencies kind)) | ||
(defmethod ^:private generate* :sarif [dependencies deps-edn-path & _] | ||
(-> dependencies (logic.sarif/generate deps-edn-path) json/generate-string println)) | ||
|
||
(defn generate [dependencies deps-edn-path kind] | ||
(generate* dependencies deps-edn-path kind)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
(ns clj-watson.logic.sarif | ||
(:require | ||
[clj-watson.logic.template :as logic.template] | ||
[clojure.java.io :as io] | ||
[clojure.string :as string])) | ||
|
||
(def ^:private sarif-boilerplate | ||
{:$schema "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json" | ||
:version "2.1.0" | ||
:runs [{:tool | ||
{:driver {:name "clj-watson" | ||
:informationUri "https://github.com/clj-holmes/clj-watson" | ||
:version "3.0.2"}}}]}) | ||
|
||
(defn ^:private advisory->sarif-rule [dependency dependency-info {{:keys [description summary identifiers cvss]} :advisory}] | ||
(let [identifier (-> identifiers first :value) | ||
; needs to remove it from here | ||
template (-> "sarif-help.mustache" io/resource slurp) | ||
help-text (logic.template/generate {:vulnerable-dependency dependency-info :identifiers identifiers} template)] | ||
[{:id identifier | ||
:name (format "VulnerableDependency%s" (-> dependency name string/capitalize)) | ||
:shortDescription {:text summary} | ||
:fullDescription {:text description} | ||
:help {:text help-text | ||
:markdown help-text} | ||
:helpUri (format "https://github.com/advisories/%s" identifier) | ||
:properties {:security-severity (-> cvss :score str)} | ||
:defaultConfiguration {:level "error"}}])) | ||
|
||
(defn ^:private dependencies->sarif-rules [dependencies] | ||
(->> dependencies | ||
(map (fn [{:keys [dependency vulnerabilities] :as dependency-info}] | ||
(->> vulnerabilities | ||
(map #(advisory->sarif-rule dependency dependency-info %)) | ||
(reduce concat)))) | ||
(reduce concat))) | ||
|
||
(defn ^:private advisory->sarif-result | ||
[filename physical-location dependency {{:keys [identifiers]} :advisory}] | ||
{:ruleId (-> identifiers first :value) | ||
:message {:text (format "Vulnerability found in direct dependency %s" dependency)} | ||
:locations [{:physicalLocation | ||
{:artifactLocation {:uri filename} | ||
:region physical-location}}]}) | ||
|
||
(defn ^:private dependencies->sarif-results [dependencies deps-edn-path] | ||
(->> dependencies | ||
(map (fn [{:keys [dependency vulnerabilities physical-location]}] | ||
(->> vulnerabilities | ||
(map #(advisory->sarif-result deps-edn-path physical-location dependency %))))) | ||
(reduce concat))) | ||
|
||
(defn generate [dependencies deps-edn-path] | ||
(let [rules (dependencies->sarif-rules dependencies) | ||
results (dependencies->sarif-results dependencies deps-edn-path)] | ||
(-> sarif-boilerplate | ||
(assoc-in [:runs 0 :tool :driver :rules] rules) | ||
(assoc-in [:runs 0 :results] results)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(ns clj-watson.logic.template | ||
(:require | ||
[clj-watson.logic.formatter :refer [dependencies-hierarchy-to-tree]] | ||
[selmer.filters :refer [add-filter!]] | ||
[selmer.parser :refer [render]])) | ||
|
||
(add-filter! :build-tree dependencies-hierarchy-to-tree) | ||
|
||
(defn generate [dependencies template] | ||
(render template dependencies)) |