FiCl Dev Blog한국어

[PR #84] Admin Requests Accept Only JSON Bodies

Work completed 2026-10-22 14:50 KST · Published 2026-10-23 13:27 KST · AI model used for the work Claude Sonnet 5.5

[PR #84] Admin Requests Accept Only JSON BodiesWhy requests from other sites' forms are blocked at the admin server entrance, and the choices madePR #84Admin Requests AcceptOnly JSON BodiesOther body formats rejected at the entranceI requestedClaude added checkRejected with 415Tests passed1ChosenAdded to the existing origin checkBodyless logout unchanged2RejectedCheck in each controllerChanging the body parserNot verifiedNo Docker here, so full tests were confirmed by CINo extra tests for chunked bodies or PUT, PATCH, DELETEKeyOne shared entrance check means new admin features get it automatically.FiCl Dev Blog · Post summary figure
[PR #84] Admin Requests Accept Only JSON BodiesWhy requests from other sites' forms are blocked at the admin server entrance, and the choices madePR #84Admin Requests AcceptOnly JSON BodiesOther body formats rejected at the entranceI requestedClaude added checkRejected with 415Tests passed1ChosenAdded to the existing origin checkBodyless logout unchanged2RejectedCheck in each controllerChanging the body parserNot verifiedNo Docker here, so full tests were confirmed by CINo extra tests for chunked bodies or PUT, PATCH, DELETEKeyOne shared entrance check means new admin features get it automatically.FiCl Dev Blog · Post summary figure

What and why

I requested this work, and Claude implemented it.

A web page on another site can send requests to an admin address through the user’s browser. This kind of attack, which borrows the permissions of a logged-in user without their knowledge, is called cross-site request forgery (CSRF). The gap was found during the review of the earlier PR #82.

An origin check (Origin, which checks the address of the site that sent the request) was already in place. But when the origin matched, even a body that was not JSON went through to the controller. Browsers do not ask for permission first (a CORS preflight) for ordinary form submissions, so a form on another site could come in this way. A text/plain body even caused an internal server error, 500.

So a body-format check was added after the origin check. Whether a body exists is judged in two ways: if Content-Length (a header that states the body length) is greater than 0, or if Transfer-Encoding (a header saying the body is sent in pieces) is present, a body exists. A logout with no body (204, success with nothing to return) still works. The Content-Type (the header that states the body format) must be application/json, and options after it such as charset are allowed.

Chosen approach and rejected alternatives

Choice Approach Reason
Chosen Add the check to the existing guard in one place Later admin controllers are covered automatically
Rejected Add the check to each controller Easy to forget on a new controller
Rejected Change the body parser’s settings Depends on the order the parser runs in, so it breaks easily later

How it was checked

Lessons