clojure - When is the ring anti-forgery token inserted? -
i'm trying understand when ring anti-forgery token generated or inserted in html page. i'm using compojure / ring / hiccup take question ring. don't have problem per se: want know when , how anti-forgery token "injected".
the anti-forgery-field function ring.util.anti-forgery implemented this:
(html (hidden-field "__anti-forgery-token" *anti-forgery-token*) if call function @ repl get:
repl> (println (anti-forgery-field)) <input id="__anti-forgery-token" name="__anti-forgery-token" type="hidden" value="unbound: #'ring.middleware.anti-forgery/*anti-forgery-token*" /> still @ repl, if try var same "unbound" variable:
> ring.middleware.anti-forgery/*anti-forgery-token* => #object[clojure.lang.var$unbound 0x1eae055 "unbound: #'ring.middleware.anti-forgery/*anti-forgery-token*"] what don't understand "unbound" value nor when transformed (by ring?) actual token delivered. , don't understand how several users connecting website get, each, different token (per session).
is variable "unbound"? when/how become "bound" (if does?)?
also, if i've got ring session id (say "ring-session=310678be-9ef6-41a7-a12a-b2417de4a79f"), how can see, @ clojure repl (on server side), corresponding anti-forgery token's value?
it bound in context (dynamic environment, current stack, if will) of individual request. think of thread-local variable/binding. not in context of request while looking @ application state repl.
it must way, because has different value each user. you'd simulate similar behaviour through explicit lookup call, if working in environment not allow kind of control of dynamic environment.
the binding right session value established in middleware during request, here:
(binding [*anti-forgery-token* (session-token request)] ;; ... )
Comments
Post a Comment