Skip to content

Commit

Permalink
Merge pull request #28 from m3tti/master
Browse files Browse the repository at this point in the history
Remove dependency on crypto-random
  • Loading branch information
weavejester committed Jan 24, 2025
2 parents 5e2aa77 + 134c95d commit 00c65c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
:license {:name "The MIT License"
:url "http://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure "1.9.0"]
[crypto-random "1.2.1"]
[crypto-equality "1.0.1"]
[hiccup "1.0.5"]]
:plugins [[lein-codox "0.10.8"]]
Expand Down
12 changes: 9 additions & 3 deletions src/ring/middleware/anti_forgery/session.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(ns ring.middleware.anti-forgery.session
"Contains the synchronizer token (or session) strategy."
(:require [ring.middleware.anti-forgery.strategy :as strategy]
[crypto.equality :as crypto]
[crypto.random :as random]))
[crypto.equality :as crypto]))

(defn- random-base64 [buffer-size]
(let [random (java.security.SecureRandom.)
base64 (.withoutPadding (java.util.Base64/getEncoder))
buffer (byte-array buffer-size)]
(.nextBytes random buffer)
(.encodeToString base64 buffer)))

(defn- session-token [request]
(get-in request [:session :ring.middleware.anti-forgery/anti-forgery-token]))
Expand All @@ -11,7 +17,7 @@
strategy/Strategy
(get-token [this request]
(or (session-token request)
(random/base64 60)))
(random-base64 60)))

(valid-token? [_ request token]
(when-let [stored-token (session-token request)]
Expand Down

0 comments on commit 00c65c7

Please sign in to comment.