Skip to content

Commit c8d7108

Browse files
committed
Update rest.txt example to include headers required for CSRF
validation. Update config doc: X-Requested-With is used with rest as well as xmlrpc.
1 parent e81058c commit c8d7108

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

doc/rest.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ with a REST API supporting JSON encoding::
170170
... exit(1)
171171
>>> print (r.json() ['data']['data']
172172
TEST Title
173-
>>> r = s.post (u + 'issue', data = dict (title = 'TEST Issue'))
173+
>>> h = {'X-Requested-With': 'rest', 'Referer': 'http://tracker.example.com/demo/'}
174+
>>> r = s.post (u + 'issue', data = dict (title = 'TEST Issue'), headers=h)
174175
>>> if not 200 <= r.status_code <= 201:
175176
... print("Failed: %s: %s" % (r.status_code, r.reason))
176177
... exit(1)
@@ -184,14 +185,19 @@ Retire/Restore::
184185
>>> print("ETag: %s" % etag)
185186
>>> etag = r.json()['data']['@etag']
186187
>>> print("@etag: %s" % etag)
187-
>>> h = {'If-Match': etag}
188+
>>> h = {'If-Match': etag, 'X-Requested-With': 'rest', 'Referer': 'http://tracker.example.com/demo/'}
188189
>>> d = {'@op:'action', '@action_name':'retire'}
189190
>>> r = s.patch(u + 'issue/42', data = d, headers = h)
190191
>>> print(r.json())
191192
>>> d = {'@op:'action', '@action_name':'restore'}
192193
>>> r = s.patch(u + 'issue/42', data = d, headers = h)
193194
>>> print(r.json())
194195

196+
Note the addition of headers for: x-requested-with and referer. This
197+
allows the request to pass the CSRF protection mechanism. You may need
198+
to add Origin if this check is enabled in your tracker's config.ini.
199+
200+
195201
Adding new rest endpoints
196202
=========================
197203

roundup/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def str2value(self, value):
768768
Set this to 'no' to ignore the field and accept the post.
769769
"""),
770770
(CsrfSettingOption, 'csrf_enforce_header_X-REQUESTED-WITH', "yes",
771-
"""This is only used for xmlrpc requests. This test is
771+
"""This is only used for xmlrpc and rest requests. This test is
772772
done after Origin and Referer headers are checked. It only
773773
verifies that the X-Requested-With header exists. The value
774774
is ignored.

0 commit comments

Comments
 (0)