[PR #5243] [CLOSED] feat(web): cap request body size on state-changing routes #5826

Closed
opened 2026-11-02 04:04:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5243
Author: @n0ctal
Created: 6/12/2026
Status: ❌ Closed

Base: main ← Head: claude-pr-0008-request-body-limit


📝 Commits (1)

  • 4c0824e feat(web): cap request body size on state-changing routes

📊 Changes

3 files changed (+86 additions, -0 deletions)

View changed files

➕ internal/web/middleware/bodylimit.go (+30 -0)
➕ internal/web/middleware/bodylimit_test.go (+49 -0)
📝 internal/web/web.go (+7 -0)

📄 Description

Summary

This PR adds a request body size limit for state-changing routes.

It uses http.MaxBytesReader to reject oversized request bodies before they cause unnecessary memory allocation or long processing on mutation endpoints.

Why

Even with authentication in place, large request bodies on create/update/import-style routes are an avoidable resource risk. A reasonable cap improves resilience against buggy clients and accidental oversized submissions.

Scope

  • adds body-size limiting middleware
  • applies it to state-changing requests
  • does not affect normal read-only requests

Validation

  • added tests for:
    • under-limit request bodies
    • over-limit request bodies
    • routes without request bodies

Risk

Low. This is defensive hardening and does not alter normal successful request flows.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5243 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `claude-pr-0008-request-body-limit` --- ### 📝 Commits (1) - [`4c0824e`](https://github.com/MHSanaei/3x-ui/commit/4c0824e1c2fdc8f0285f1bd67f27e954a346092d) feat(web): cap request body size on state-changing routes ### 📊 Changes **3 files changed** (+86 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `internal/web/middleware/bodylimit.go` (+30 -0) ➕ `internal/web/middleware/bodylimit_test.go` (+49 -0) 📝 `internal/web/web.go` (+7 -0) </details> ### 📄 Description ## Summary This PR adds a request body size limit for state-changing routes. It uses `http.MaxBytesReader` to reject oversized request bodies before they cause unnecessary memory allocation or long processing on mutation endpoints. ## Why Even with authentication in place, large request bodies on create/update/import-style routes are an avoidable resource risk. A reasonable cap improves resilience against buggy clients and accidental oversized submissions. ## Scope - adds body-size limiting middleware - applies it to state-changing requests - does not affect normal read-only requests ## Validation - added tests for: - under-limit request bodies - over-limit request bodies - routes without request bodies ## Risk Low. This is defensive hardening and does not alter normal successful request flows. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:22 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5826
No description provided.