forked from weavejester/ring-anti-forgery
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba288c7
commit 49a3639
Showing
3 changed files
with
14 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
(ns ring.util.anti-forgery | ||
"Utility functions for inserting anti-forgery tokens into HTML forms." | ||
(:require [hiccup.core :refer [html]] | ||
[hiccup.form :refer [hidden-field]] | ||
(:require [clojure.string :as str] | ||
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]])) | ||
|
||
(defn anti-forgery-field | ||
"Create a hidden field with the session anti-forgery token as its value. | ||
This ensures that the form it's inside won't be stopped by the anti-forgery | ||
middleware." | ||
[] | ||
(html (hidden-field "__anti-forgery-token" (force *anti-forgery-token*)))) | ||
(str "<input id=\"__anti-forgery-token\" name=\"__anti-forgery-token\"" | ||
" type=\"hidden\" value=\"" | ||
(-> (force *anti-forgery-token*) | ||
(str/replace "&" "&") | ||
(str/replace "\"" """) | ||
(str/replace "<" "<")) | ||
"\" />")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters