File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -52,11 +52,29 @@ Insert a hidden input field named `csrf_token` in your forms.
52
52
<button type="submit">Send</button>
53
53
</form>
54
54
55
+ You can also use following javascript code to perform AJAX calls (jQuery 1.5 and newer).
56
+
57
+ function csrfSafeMethod(method) {
58
+ // HTTP methods that do not require CSRF protection.
59
+ return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
60
+ }
61
+ $.ajaxSetup({
62
+ crossDomain: false,
63
+ beforeSend: function(xhr, settings) {
64
+ if (!csrfSafeMethod(settings.type)) {
65
+ xhr.setRequestHeader("X-CSRFToken", {{ .csrf_token }});
66
+ }
67
+ }
68
+ });
69
+
55
70
A demo application is provided in the samples directory. To launch it:
56
71
57
72
revel run github.com/cbonello/revel-csrf/samples/demo
58
73
59
74
## TODO
60
75
61
76
* Routes exemption.
77
+ * Logger.
78
+ * Unique token per-page.
79
+ * Configuration options.
62
80
* Test cases.
You can’t perform that action at this time.
0 commit comments