Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix npe when a vulnerability does not have a safe version #9

Merged
merged 4 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions resources/vulnerable-deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{:deps {org.clojure/clojure {:mvn/version "1.11.0-alpha1"}
com.auth0/java-jwt {:mvn/version "3.5.0"}
image-resizer/image-resizer {:mvn/version "0.1.10"}}
:aliases {:banana {:extra-deps {clj-http/clj-http {:mvn/version "3.9.1"}}}}}
image-resizer/image-resizer {:mvn/version "0.1.10"}
io.replikativ/datahike {:mvn/version "0.4.1480"}}
:aliases {:banana {:extra-deps {clj-http/clj-http {:mvn/version "3.9.1"}}}}}
28 changes: 15 additions & 13 deletions src/clj_watson/diplomat/remediate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@
(let [parents (-> parents first reverse)
root-dependency (last parents)
safe-version (-> vulnerability dependency-safe-versions first)]
(loop [parents parents
child-dependency dependency-name
child-safe-version safe-version]
(if (seq parents)
(let [parent-dependency-name (first parents)
latest-version (->> parent-dependency-name
diplomat.dependency/get-all-versions
last)]
(if (parent-dependency-contains-child-version? parent-dependency-name latest-version child-dependency child-safe-version repositories)
(recur (next parents) parent-dependency-name latest-version)
{root-dependency {:exclusions [child-dependency]}
child-dependency {:mvn/version child-safe-version}}))
{child-dependency {:mvn/version child-safe-version}}))))
(if safe-version
(loop [parents parents
child-dependency dependency-name
child-safe-version safe-version]
(if (seq parents)
(let [parent-dependency-name (first parents)
latest-version (->> parent-dependency-name
diplomat.dependency/get-all-versions
last)]
(if (parent-dependency-contains-child-version? parent-dependency-name latest-version child-dependency child-safe-version repositories)
(recur (next parents) parent-dependency-name latest-version)
{root-dependency {:exclusions [child-dependency]}
child-dependency {:mvn/version child-safe-version}}))
{child-dependency {:mvn/version child-safe-version}}))
"vulnerability without patch.")))

(defn vulnerabilities-fix-suggestions [{:keys [vulnerable-dependencies] :as dependencies} deps-edn-path]
(let [deps (-> deps-edn-path slurp edn/read-string)
Expand Down
1 change: 1 addition & 0 deletions src/clj_watson/entrypoint.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@

(comment
(scan {:deps-edn-path "resources/vulnerable-deps.edn"
:suggest-fix true
:dependency-check-properties "resources/dependency-check.properties"}))