This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-11
Channels
- # announcements (7)
- # aws (52)
- # babashka (16)
- # beginners (49)
- # bristol-clojurians (1)
- # calva (2)
- # chlorine-clover (26)
- # cider (6)
- # clara (1)
- # clj-kondo (79)
- # cljfx (15)
- # clojure (82)
- # clojure-berlin (2)
- # clojure-czech (1)
- # clojure-europe (26)
- # clojure-france (91)
- # clojure-germany (48)
- # clojure-nl (7)
- # clojure-norway (99)
- # clojure-uk (54)
- # clojurescript (18)
- # code-reviews (9)
- # data-science (2)
- # datalog (15)
- # datomic (15)
- # depstar (20)
- # emacs (4)
- # events (1)
- # fulcro (30)
- # funcool (1)
- # graphql (1)
- # helix (5)
- # jobs (6)
- # kaocha (12)
- # leiningen (8)
- # luminus (1)
- # malli (13)
- # off-topic (73)
- # pathom (12)
- # portal (11)
- # portland-or (1)
- # re-frame (10)
- # reagent (1)
- # reitit (44)
- # remote-jobs (1)
- # ring (19)
- # shadow-cljs (64)
- # tools-deps (32)
Hi there everyone. I'm trying to write a ring middleware that will check a stripe webhook callback's signature. The signature is in the header. Can get that fine. But I need to verify it by comparing it with the raw body, as that is what is signed. The raw body is json. Then if it passes, future middleware will decode the json.
The issue is that body is presented as a stream. And if I slurp the stream, then future json middleware gets an empty body content, and the stream has been consumed
how do I verify a header signature against the raw body contents, without consuming the stream?
is the best way to create a new stream and push the contents back onto it? or is there an easier way?
(defn wrap-test [handler]
(fn
([request]
(log/info "wrap-test/1")
(let [content (slurp (:body request))]
(log/info "body is" content)
(handler (assoc request :body (io/input-stream (.getBytes content))))))
([request respond raise]
(log/info "wrap-test/3")
(let [content (slurp (:body request))]
(log/info "body is" content)
(handler (assoc request :body (io/input-stream (.getBytes content))) respond raise)))))
slurps the body... but then creates a new body for subsequent processing by creating a input-stream from the contents
I guess I would have to be careful of a DoS attack with this of someone sending a multi terrabyte body...?
Why don't you validate only after it's read as JSON? And do you really need a middleware? Do you have more than one stripe webhook route?