Add validation for POST/PUT/PATCH requests

This was made on my phone
This commit is contained in:
2025-10-11 20:02:24 -04:00
parent fc9787b8ec
commit 4a6e65226e

View File

@@ -26,9 +26,20 @@ app.register_blueprint(server)
app.register_blueprint(apps) app.register_blueprint(apps)
@app.before_request @app.before_request
async def preflight(): async def validate_json():
if request.method == "OPTIONS": 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 @app.after_request
async def handle_logging(response): async def handle_logging(response):