Repository navigation
fix(backend): return 404 instead of panicking on unresolvable static paths - #858
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
…paths serveFilesHandler stats the requested file and only handled os.IsNotExist errors. Every other error left fileInfo nil, so the following fileInfo.IsDir() call panicked. LoggingMiddleware recovered the panic and answered 500 while logging a full stack trace. Ordinary bad URLs hit this path: - /index.html/foo: a path component is a regular file, so stat fails with ENOTDIR, which os.IsNotExist does not cover; - a path segment longer than NAME_MAX fails with ENAMETOOLONG. Treat ENOTDIR and ENAMETOOLONG like a missing file and render the 404 page. Any other stat error (for example permission denied) is now passed to http.FileServer, which maps it to the proper status code instead of dereferencing a nil FileInfo. Add a table test for serveFilesHandler covering existing and missing files, a path below a regular file, an overlong segment and a directory without index.html. Fixes werf#857 Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
NopeCharon
force-pushed
the
fix/backend/static-path-panic
branch
from
October 27, 2026 09:57
87b1341 to
20864ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #857
Problem
serveFilesHandleronly handledos.IsNotExisterrors fromos.Stat. Any other error leftfileInfonil, and the followingfileInfo.IsDir()call panicked.LoggingMiddlewarerecovered the panic, answered500and logged a stack trace.Ordinary bad URLs trigger this:
/index.html/foo:ENOTDIR, because a path component is a regular fileENAMETOOLONGChanges
ENOTDIRandENAMETOOLONGlike a missing file and render the 404 page.http.FileServer, which maps it to the right status code. This replaces the nil dereference.TestServeFilesHandler, which covers existing and missing files, a path below a regular file, an overlong segment and a directory withoutindex.html. Without the fix the test panics on the/page.html/foocase.Validation
go test ./...passes inbackend/on Linux (arm64) and macOS.gofumpt -extra,gci(Standard/Default/github.com/werf/) andgolangci-lintv1.62.0 with the common-ci config report nothing new. The only remaining finding, the unusedgetRootRelease, was there before this change.root/en:/index.html/fooand a 300-character path now return404with404.html. Before, they returned500.