[PR #5609] [MERGED] fix(web): don't let an empty skip-suffix disable the request body cap #5926

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5609
Author: @n0ctal
Created: 6/27/2026
Status: ✅ Merged
Merged: 6/28/2026
Merged by: @MHSanaei

Base: main ← Head: pr-bodylimit-empty-suffix


📝 Commits (4)

  • 1058c90 fix(web): tighten database restore body-cap exemption
  • 6ae3dab Merge branch 'main' into pr-bodylimit-empty-suffix
  • eaef727 Merge branch 'main' into pr-bodylimit-empty-suffix
  • 3535d26 Merge branch 'main' into pr-bodylimit-empty-suffix

📊 Changes

3 files changed (+19 additions, -18 deletions)

View changed files

📝 internal/web/middleware/bodylimit.go (+4 -5)
📝 internal/web/middleware/bodylimit_test.go (+12 -10)
📝 internal/web/web.go (+3 -3)

📄 Description

Summary

MaxBodyBytes(limit, skipSuffixes...) exempts a request when its path ends in one of skipSuffixes. An empty string in that list makes strings.HasSuffix(path, "") always true, so a single empty suffix silently disables the body-size cap for every route. This adds a suffix != "" guard and tightens the matcher (hasAnySuffix).

Why

The body cap protects state-changing routes from unbounded request bodies (memory/DoS). An accidental empty entry in the skip list (e.g. from a config/format slip) removes that protection globally and silently.

Scope

  • internal/web/middleware/bodylimit.go: skip a path only when a non-empty configured suffix matches.
  • internal/web/middleware/bodylimit_test.go: assert a sub-path of an exempt route (/importDB/other) is not exempt and that over-limit bodies on non-exempt paths are still capped.
  • internal/web/web.go: minor call-site cleanup.

Validation

go test ./internal/web/middleware passes (incl. the new sub-path/empty-suffix cases).

Risk

Minimal. Exempt routes still work; only the unintended global bypass is closed.


🔄 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/5609 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/27/2026 **Status:** ✅ Merged **Merged:** 6/28/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `pr-bodylimit-empty-suffix` --- ### 📝 Commits (4) - [`1058c90`](https://github.com/MHSanaei/3x-ui/commit/1058c902160519bfbff613d91739eddd5c38dd36) fix(web): tighten database restore body-cap exemption - [`6ae3dab`](https://github.com/MHSanaei/3x-ui/commit/6ae3dab3a6409ca8ee8cabfc90f575dcdd66c87d) Merge branch 'main' into pr-bodylimit-empty-suffix - [`eaef727`](https://github.com/MHSanaei/3x-ui/commit/eaef72765609145e1868841572166d6571649388) Merge branch 'main' into pr-bodylimit-empty-suffix - [`3535d26`](https://github.com/MHSanaei/3x-ui/commit/3535d2672ca7b1f5eafac17be9f3ab08507ec753) Merge branch 'main' into pr-bodylimit-empty-suffix ### 📊 Changes **3 files changed** (+19 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/middleware/bodylimit.go` (+4 -5) 📝 `internal/web/middleware/bodylimit_test.go` (+12 -10) 📝 `internal/web/web.go` (+3 -3) </details> ### 📄 Description ## Summary `MaxBodyBytes(limit, skipSuffixes...)` exempts a request when its path ends in one of `skipSuffixes`. An empty string in that list makes `strings.HasSuffix(path, "")` always true, so a single empty suffix silently disables the body-size cap for **every** route. This adds a `suffix != ""` guard and tightens the matcher (`hasAnySuffix`). ## Why The body cap protects state-changing routes from unbounded request bodies (memory/DoS). An accidental empty entry in the skip list (e.g. from a config/format slip) removes that protection globally and silently. ## Scope - `internal/web/middleware/bodylimit.go`: skip a path only when a **non-empty** configured suffix matches. - `internal/web/middleware/bodylimit_test.go`: assert a sub-path of an exempt route (`/importDB/other`) is **not** exempt and that over-limit bodies on non-exempt paths are still capped. - `internal/web/web.go`: minor call-site cleanup. ## Validation `go test ./internal/web/middleware` passes (incl. the new sub-path/empty-suffix cases). ## Risk Minimal. Exempt routes still work; only the unintended global bypass is closed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:05 +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#5926
No description provided.