Skip to content

fix(server): cap insert_assets request bodies - #558

Merged
BaaRai merged 2 commits into
BaaRai:mainfrom
Coff0xc:fix/insert-assets-body
Nov 26, 2026
Merged

BaaRai merged 2 commits into
BaaRai:mainfrom
Coff0xc:fix/insert-assets-body

Conversation

@Coff0xc

@Coff0xc Coff0xc commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

POST /api/assets decoded the body with json.NewDecoder on its own. The JSON body middleware skips multipart/ so uploads can stream, and this handler inherited that skip. A multipart request could therefore be an uncapped JSON document.

The handler now uses the shared decoder, which applies the existing cap, and answers 413 before it checks the database. The multipart exemption for real uploads is unchanged.

go test -count=1 -run "TestInsertAssetsCapsMultipartBody|TestDecodeCapsBody|TestMultipartBodyIsNotGivenTheJSONCap|TestRawJSONBodyOverTheCapIs413|TestDecodeAcceptsSmallBody" ./server/ passed.

POST /api/assets decoded with json.NewDecoder directly. A multipart
Content-Type skips the JSON body middleware, so that request was uncapped.
Decode through the shared limit first and answer 413 before touching the
database.
@5P34R

5P34R commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review notes

The change to insertAssets is correct (decoding now happens before the 503 DB check, which is harmless). The underlying gap is in the middleware, though, so this fixes 1 of about 30 affected handlers.

limitRequestBody skips any request with a multipart Content-Type (server/server_mgmt.go:134). Every handler that calls json.NewDecoder(r.Body) directly is uncapped when the client sends a multipart Content-Type with a JSON body.

#575 caps multipart bodies in the middleware at the largest upload-handler limit, which covers all of them. This PR is still a reasonable tighter per-handler cap on top of that.

@BaaRai
BaaRai force-pushed the fix/insert-assets-body branch from 76f30d1 to 9ef4e06 Compare November 26, 2026 22:24
BaaRai added a commit to gabrimarch3/ARTEX that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai force-pushed the fix/insert-assets-body branch from 9ef4e06 to 7028595 Compare November 26, 2026 22:40
BaaRai added a commit to gabrimarch3/ARTEX that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai merged commit 56a887e into BaaRai:main Nov 26, 2026
6 checks passed
@BaaRai

BaaRai commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Merged, thanks @Coff0xc. Rebased on current main and verified with its tests and negative control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants