Add validation for POST/PUT/PATCH requests
This was made on my phone
This commit is contained in:
@@ -26,9 +26,20 @@ app.register_blueprint(server)
|
||||
app.register_blueprint(apps)
|
||||
|
||||
@app.before_request
|
||||
async def preflight():
|
||||
async def validate_json():
|
||||
if request.method == "OPTIONS":
|
||||
return "", 204
|
||||
return "", 200
|
||||
|
||||
elif request.method in ["PUT", "POST", "PATCH"]:
|
||||
if "media" in request.path:
|
||||
# Don't check media uploads
|
||||
return
|
||||
|
||||
try:
|
||||
request.get_json(force=True)
|
||||
except Exception as e:
|
||||
return jsonify({"error": "Content not JSON.", "errcode": "M_NOT_JSON"}), 400
|
||||
|
||||
|
||||
@app.after_request
|
||||
async def handle_logging(response):
|
||||
|
||||
Reference in New Issue
Block a user