mirror of
https://github.com/donlon/cloudflare-error-page.git
synced 2025-12-19 14:59:28 +00:00
editor/server: add simple CSRF check
This commit is contained in:
@@ -65,7 +65,19 @@ def get_rand_name(digits=8):
|
|||||||
def create():
|
def create():
|
||||||
if len(request.data) > 4096:
|
if len(request.data) > 4096:
|
||||||
abort(413)
|
abort(413)
|
||||||
|
|
||||||
|
# Simple CSRF check
|
||||||
|
sec_fetch_site = request.headers.get('Sec-Fetch-Site')
|
||||||
|
if sec_fetch_site is not None and sec_fetch_site != 'same-origin':
|
||||||
|
return jsonify({
|
||||||
|
'status': 'failed',
|
||||||
|
'message': 'CSRF check failed (Sec-Fetch-Site)',
|
||||||
|
}), 403
|
||||||
|
|
||||||
|
# Accessing request.json raises 415 error if Content-Type is not application/json. This also prevents CSRF requests.
|
||||||
|
# See https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/CSRF#avoiding_simple_requests
|
||||||
params = request.json['parameters'] # throws KeyError
|
params = request.json['parameters'] # throws KeyError
|
||||||
|
|
||||||
# TODO: strip unused params
|
# TODO: strip unused params
|
||||||
try:
|
try:
|
||||||
item = models.Item()
|
item = models.Item()
|
||||||
|
|||||||
Reference in New Issue
Block a user