Skip to content

backport PR 3016 from v5 to v4#3019

Merged
aldas merged 1 commit into
labstack:v4from
aldas:v4_backport_3016
Jun 15, 2026
Merged

backport PR 3016 from v5 to v4#3019
aldas merged 1 commit into
labstack:v4from
aldas:v4_backport_3016

Conversation

@aldas

@aldas aldas commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

backport PR #3016 from v5 for GHSA-vfp3-v2gw-7wfq


Make serving static file releated methods and middleware not unescape path by default - so how the way Router interprets paths and Static methods/middleware is consistent.

Given following situation:

// 0.
// given folder structure:
// private.txt
// public/
// public/index.html
// public/text.txt
// public/admin/private.txt

// 1. share `public/` folder contents from the server root. This folder actually contains subfolder `admin` which
// contents we want to forbid from downloading
e.Static("/", "public")

// 2. naively assume that everything under /admin folder is now forbidden
e.GET("/admin/*", func(c *Context) error {
    return ErrForbidden
})

Then requests to /admin%2fprivate.txt would not be matched to GET /admin/* route (routing does not look unescaped path) and static file serving will use unescaped path to serve the file.

Note: this way of "guarding" subfolders will never work for for paths like /assets/../admin%2fprivate.txt which will path.Clean("/assets/../admin%2fprivate.txt") to /admin/private.txt and are servable if static file serving is configured to unescape paths.

If you want to guard routes - use middlewares on Static* methods and before Static middleware.

Breaking change / migration: If you serve files whose names contain URL-encoded characters (e.g., /hello%20world.txthello world.txt), you must now opt in:

	e := echo.New()
	e.EnablePathUnescapingStaticFiles = true  // <-- enable old behavior
	e.Static("/", "public")

for static middleware

	e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
		EnablePathUnescaping: true, // <-- enable old behavior
	}))

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.53%. Comparing base (9afa4ba) to head (d16a4ec).
⚠️ Report is 1 commits behind head on v4.

Files with missing lines Patch % Lines
middleware/static.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v4    #3019      +/-   ##
==========================================
- Coverage   93.55%   93.53%   -0.02%     
==========================================
  Files          43       42       -1     
  Lines        4312     4299      -13     
==========================================
- Hits         4034     4021      -13     
  Misses        159      159              
  Partials      119      119              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aldas aldas merged commit 13f0ed1 into labstack:v4 Jun 15, 2026
9 of 10 checks passed
@aldas aldas deleted the v4_backport_3016 branch June 15, 2026 18:16
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.

1 participant