Skip to content

Commit

Permalink
Fixes issue #32 ("anti-forgery-token is encoded but not decoded") - r…
Browse files Browse the repository at this point in the history
…eplaces non-URL-safe chars in base64 CSRF key
  • Loading branch information
ddellacosta committed Dec 4, 2014
1 parent a0d2b0b commit 7ce5a1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/friend_oauth2/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require
[cheshire.core :refer [parse-string]]
[ring.util.codec :as ring-codec]
[clojure.string :refer [split join]]
[clojure.string :as string :refer [split join]]
[crypto.random :as random]))

(defn format-config-uri
Expand Down Expand Up @@ -43,4 +43,4 @@
(defn generate-anti-forgery-token
"Generates random string for anti-forgery-token."
[]
(-> (random/base64 60) (split #"/") join))
(string/replace (random/base64 60) #"[\+=/]" "-"))
6 changes: 6 additions & 0 deletions test/friend_oauth2/util_facts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@
"Replaces the authorization code"
((oauth2-util/replace-authz-code (uri-config-fixture :access-token-uri) "my-code") :code)
=> "my-code")

(fact
"Replaces '+', '/' and '=' in base64 CSRF token."
(with-redefs [crypto.random/base64 (constantly "TaUtFckiPp+v7yRx8aYC5OGAU1k/UouWtqI7e9IH8pUtm2/r00d5YVFy+JdS8zaWuMS=j0dwNDHt4vym")]
(let [correct-token "TaUtFckiPp-v7yRx8aYC5OGAU1k-UouWtqI7e9IH8pUtm2-r00d5YVFy-JdS8zaWuMS-j0dwNDHt4vym"]
(oauth2-util/generate-anti-forgery-token) => correct-token)))

0 comments on commit 7ce5a1a

Please sign in to comment.