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

Removes dependecy of apache-commons to enable babashka users to use ring-anti-forgery #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:paths ["src"]
:deps
{crypto-equality/crypto-equality {:mvn/version "1.0.1"}
hiccup/hiccup {:mvn/version "1.0.5"}}}
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/getUrlEncoder))
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