Closed donbonifacio closed 9 years ago
Thank you for your reporting. I'll review it.
Most (hopefully all?) implementations now have a basic check to prevent this attack: if a secret key was provided, then token verification will fail for tokens using the none algorithm.
Currently, clj-jwt does not allows to specify key to verify not signed token (:none
algorithm).
clj-jwt handles public key as an object of bouncycastle, so verifying :HS256
signed token with RSA public key will fail.
I tested clj-jwt codes with following test case and it is not vulnerable.
(ns clj-jwt.attack-test
(:require
[clj-jwt.core :refer :all]
[clj-jwt.sign :refer :all]
[clj-jwt.key :refer [private-key public-key]]
[clojure.string :as str]
[clojure.test :refer :all]))
(def pub-key-path "test/files/rsa/no_pass.pub.key")
(def rsa-prv-key (private-key "test/files/rsa/no_pass.key"))
(def rsa-pub-key (public-key pub-key-path))
(deftest test-algorithm->none-attack
(let [key "secret"
original (-> {:foo "bar"} jwt (sign :HS256 key))
attacked (update-in original [:header :alg] (constantly "none"))]
(is (verify original key))
(is (not (verify attacked key)))))
(deftest test-rsa->hmac-attack
(let [base (jwt {:foo "bar"})
original (sign base :RS256 rsa-prv-key)
hmac-sign (-> base (sign :HS256 (str/trim (slurp pub-key-path))) :signature)
attacked (-> original
(update-in [:header :alg] (constantly "HS256"))
(update-in [:signature] (constantly hmac-sign)))]
(is (verify original rsa-pub-key))
(is (thrown? Exception (verify attacked rsa-pub-key)))))
algorithm
to verify algorithm in token header.Great work @liquidz :)
ToDo
- Add optional parameter that specifies algorithm to verify algorithm in token header.
I supported this optional parameter in ver 0.0.13.
Hello, Are you aware of this: https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/