Commit Graph

1932 Commits

Author SHA1 Message Date
dependabot[bot] d6a99db432 chore(deps): bump securego/gosec from 2.25.0 to 2.26.1 (#2195)
Bumps [securego/gosec](https://github.com/securego/gosec) from 2.25.0 to 2.26.1.
- [Release notes](https://github.com/securego/gosec/releases)
- [Commits](https://github.com/securego/gosec/compare/v2.25.0...v2.26.1)

---
updated-dependencies:
- dependency-name: securego/gosec
  dependency-version: 2.26.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-29 09:04:46 +02:00
Erik Dubbelboer f36c900902 header: match net/http CL+TE handling (#2190)
Match net/http behavior when requests or responses contain both
Content-Length and Transfer-Encoding.

Parse and validate Content-Length even when Transfer-Encoding is present, so
invalid lengths are rejected. For valid Content-Length with chunked
Transfer-Encoding, keep chunked framing as authoritative. Also apply the same
precedence when RequestHeader.DisableSpecialHeader is used.
2026-04-28 04:33:01 +02:00
Erik Dubbelboer 0b4cede30f header: reject unsupported response Transfer-Encoding (#2192)
Reject HTTP/1.1 response Transfer-Encoding values unless they are a single
chunked header, matching net/http's strict transfer parser behavior.

This prevents arbitrary or compound response Transfer-Encoding values from
being silently normalized to chunked and avoids desync/body parsing ambiguity
when parsing upstream responses.
2026-04-28 04:28:05 +02:00
Erik Dubbelboer c497746f7d http: reject whitespace before chunk extensions (#2193)
Reject space and tab between the chunk-size and chunk-extension separator while
preserving net/http-compatible trailing OWS before CRLF.

This avoids parser divergence for chunk lines such as "3 ;ext\r\n" without
breaking the existing acceptance of padded chunk-size lines like "3 \r\n".
Add parser regression coverage for both accepted and rejected forms.
2026-04-28 04:27:54 +02:00
Erik Dubbelboer 97b38d3a48 server: document SaveMultipartFile path trust requirement 2026-04-27 07:36:20 +02:00
Yevgeniy Miretskiy 19e4b24955 feat: add ExpectHandler for richer Expect: 100-continue handling (#2175)
* feat: add ExpectHandler for richer Expect: 100-continue handling

ContinueHandler only returns a bool, limiting the server to either
accepting (100) or rejecting with 417. ExpectHandler allows returning
any HTTP status code, and closes the connection on rejection since
the client may have already started sending body data per RFC 9110.

ExpectHandler takes precedence when both handlers are set.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: use *RequestCtx in ExpectHandler for richer access

Allows callers to inspect RemoteAddr, TLS state, or any other
connection metadata alongside headers, addressing reviewer feedback.
Documents that the response must not be modified by the handler.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* Update server.go

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>

* Update server.go

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2026-04-27 05:58:04 +02:00
Erik Dubbelboer 00410e7309 Sanitize cookie setters to prevent CRLF injection (#2185)
Prevent cookie APIs from serializing embedded CR or LF bytes into
Cookie and Set-Cookie header lines.

Route Cookie key, value, domain, and path setters, parsed cookie
fields, and RequestHeader/ResponseHeader SetCookie paths through the
existing newline sanitization. Sanitize paths after normalization so
percent-decoded CR/LF bytes cannot bypass the guard.

Thanks to @vnykmshr for reporting this issue.
2026-04-27 05:29:14 +02:00
Erik Dubbelboer 3ac3b24635 server: keep hijacked reader out of pool (#2184)
When KeepHijackedConns is enabled, the hijacked connection may outlive the
HijackHandler. The wrapper continues reading through the buffered reader
after the handler returns, so returning that reader to the pool can let
another connection reset it while the hijacked connection is still in use.

Keep the buffered reader owned by the escaped hijacked connection in
keep-open mode. Add a regression test that forces reader-pool reuse
and verifies buffered data remains available after the handler returns.
2026-04-27 05:28:40 +02:00
Erik Dubbelboer 19b39dd08a Sanitize redirect Location header to prevent CRLF injection (#2186)
Route RequestCtx.Redirect Location updates through the canonical response
header setter so CR and LF bytes are normalized before serialization.

Add regression coverage for query-only and fragment-only redirects containing
CRLF, and verify the serialized response cannot emit an injected header line.
2026-04-27 05:28:30 +02:00
Erik Dubbelboer b8d29bee6e header: reject pre-colon whitespace in request headers (#2187)
Reject request header field names with whitespace immediately before the
colon instead of trimming them before special-header handling.

This prevents parser differentials for malformed framing and routing
headers such as Content-Length, Transfer-Encoding, and Host when a frontend
forwards raw invalid request headers.

Keep the existing response and trailer compatibility behavior unchanged, and
add regression coverage for both header-only parsing and full request body
reads.
2026-04-27 05:28:18 +02:00
Erik Dubbelboer 52131689e9 header: reject invalid trailer names (#2188)
Validate trailer names added through AddTrailerBytes before storing them
for Trailer header serialization.

Trim OWS around comma-separated trailer names, reject names containing
bytes outside the HTTP field-name token set, and keep the existing
forbidden-trailer filtering in place. This prevents CRLF injection through
dynamic trailer names while preserving valid trailer declarations.

Add request and response regression coverage for invalid trailer names and
tab-trimmed OWS.
2026-04-27 05:28:07 +02:00
Erik Dubbelboer 1f00bc7c28 server: apply ReadTimeout before first byte with ReduceMemoryUsage (#2183)
On new connections with ReduceMemoryUsage enabled, serveConn could reach
acquireByteReader before installing a read deadline. That left the first
blocking read outside ReadTimeout and allowed silent clients to keep the
connection open until some external timeout closed it.

Apply ReadTimeout before the first read on a new connection, while keeping
the existing idle-timeout behavior for keep-alive requests. Add a regression
test that verifies the server closes a silent ReduceMemoryUsage connection
after the first-byte timeout.
2026-04-25 03:02:03 +02:00
Erik Dubbelboer 3eab931bf1 Sanitize first-line header setters to prevent CRLF injection (#2182)
Prevent request and response first-line setters from serializing
embedded CR or LF bytes into the start line.

Route SetMethod, SetRequestURI, SetProtocol, and SetStatusMessage
through the existing newline sanitization used by other header-value
setters. This preserves behavior for valid inputs while preventing
header injection through malformed first-line values.

Thanks to @vnykmshr for reporting this issue.
2026-04-25 03:01:52 +02:00
Erik Dubbelboer 6cd91f311b Match net/http sensitive header redirect policy (#2181)
* Match net/http sensitive header redirect policy

Strip sensitive headers in DoRedirects matching net/http's redirect policy.

Reported by @vnykmshr

* Add more headers
2026-04-25 03:01:41 +02:00
Max Denushev c2e2a6c3e5 feat(client): add RetryIfErrUpstream function to handle upstream information (#2176)
* feat(client): add RetryIfErrUpstream function to handle upstream information on retry

* feat(client): lint

* feat(client): review comment fixes

* feat(client): lint

* feat(client): lint

---------

Co-authored-by: Max Denushev <denushev@tochka.com>
2026-04-20 15:38:48 +09:00
Erik Dubbelboer 534461ad12 fasthttpproxy: reject CRLF in HTTP proxy CONNECT target (#2174)
Reject dial target addresses containing CR or LF before building the
HTTP CONNECT request in httpProxyDial.

This prevents header injection through HTTP proxies when callers pass
unsanitized target addresses via low-level dial paths such as
HostClient.Addr or direct proxy dialer usage.

Reported by https://github.com/OLU-DEVX
v1.70.0
2026-04-05 07:03:35 +02:00
Erik Dubbelboer 267e740f56 fs: reject '..' path segments in rewritten paths (#2173)
Rewritten FS paths were only checked for the "/../" substring, which
allowed leading "../" values to bypass the traversal guard.

Reject any rewritten path containing a ".." path segment before joining
it with FS.Root. This closes the PathRewrite/NewPathPrefixStripper escape
in the default OS-backed handler and keeps rewritten paths within the
intended static root.

This vulnerability was discovered and reported by bugbunny.ai
2026-04-05 07:03:25 +02:00
Erik Dubbelboer a95a1ad11c Only normalize pre-colon whitespace for HTTP headers (#2172)
Keep headerScanner strict so malformed MIME header lines are still rejected.

Move trimming before ':' into the HTTP header handling paths that
intentionally normalize header names, and add a fuzz seed for the
regression case.
2026-04-04 04:24:04 +02:00
Corné Steenhuis ab8c2aceea fix: detect master process death in prefork children (#2158)
* fix: detect master process death in prefork children

Prefork child processes had no mechanism to detect if the master process
died unexpectedly. Children would become orphans, get reparented to
PID 1, and keep running silently with no supervision.

Add a watchMaster goroutine that stores the original parent PID at
startup and exits when the parent PID changes, matching the approach
used in gofiber/fiber.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add integration test for watchMaster orphan detection

Verifies that prefork children exit when the master process is killed,
using a two-level subprocess chain (test → master → child) with pipe-based
synchronization to ensure the child has recorded its PPID before the
master is killed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: pass masterPID to watchMaster and clean up tests

Capture PPID before launching the goroutine to eliminate a race between
the PPID snapshot and the ready signal. Align test style with the rest
of the project (t.Parallel, naming, ASCII-only comments).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: make prefork orphan detection configurable via OnMasterDeath callback

Address review feedback: make watchMaster opt-in via an OnMasterDeath
callback field (nil/off by default for backwards compatibility). Users
can set DefaultOnMasterDeath for os.Exit(1) or provide custom cleanup.
Also fixes ticker leak in watchMaster.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* address review feedback: remove DefaultOnMasterDeath, delete tests, fix log message

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 16:59:29 +09:00
RW c4569c5fbb feat: enhance performance (#2135)
* feat: enhance performance

* fix: improve request URI parsing condition

* feat: validate HTTP date parsing and optimize status code length calculation

* Address parsing and lint issues

* chore: update Go version to 1.24.x in CI configuration

* feat: enhance HTTP date parsing and request URI handling

* refactor: optimize month and day name parsing using bitwise operations

* refactor: replace cookie token comparison with case insensitive function and streamline request URI parsing

* refactor: streamline request body handling and simplify request URI assignment

* chore: update Go version to 1.25.x in CI configuration

* feat: add fuzz testing for HTTP date parsing to improve robustness

* refactor: avoid unused return values in HTTP date parsing benchmarks

* refactor: update HTTP date parsing to use http.TimeFormat for consistency
2026-04-01 16:19:26 +09:00
dependabot[bot] beab280ed3 chore(deps): bump github.com/andybalholm/brotli from 1.2.0 to 1.2.1 (#2170)
Bumps [github.com/andybalholm/brotli](https://github.com/andybalholm/brotli) from 1.2.0 to 1.2.1.
- [Commits](https://github.com/andybalholm/brotli/compare/v1.2.0...v1.2.1)

---
updated-dependencies:
- dependency-name: github.com/andybalholm/brotli
  dependency-version: 1.2.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-01 16:15:58 +09:00
Erik Dubbelboer 82254a7add Normalize framing header names with pre-colon whitespace 2026-03-28 07:08:16 +01:00
Erik Dubbelboer 611132707f Strict HTTP version validation and simplified first line parsing (#2167) 2026-03-28 04:31:32 +01:00
Erik Dubbelboer eb38f5fc14 HTTP1/1 requires exactly one Host header (#2164)
Bring our parser more in line with net/http.
2026-03-28 03:10:37 +01:00
Erik Dubbelboer 7d90713bda Validate request URI format during header parsing to reject malformed requests (#2168) 2026-03-28 03:10:23 +01:00
Erik Dubbelboer 3c43293b0c Prevent chunk extension request smuggling (#2165) 2026-03-28 03:10:11 +01:00
Mikhail 95dcc31d24 docs: added httpgo to related projects (#2169)
Co-authored-by: Mikhail Rybnikov <m.rybnikov@fbs.com>
2026-03-26 13:46:45 +09:00
dependabot[bot] 389cba6472 chore(deps): bump github.com/klauspost/compress from 1.18.4 to 1.18.5 (#2166)
Bumps [github.com/klauspost/compress](https://github.com/klauspost/compress) from 1.18.4 to 1.18.5.
- [Release notes](https://github.com/klauspost/compress/releases)
- [Commits](https://github.com/klauspost/compress/compare/v1.18.4...v1.18.5)

---
updated-dependencies:
- dependency-name: github.com/klauspost/compress
  dependency-version: 1.18.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-23 06:07:01 +01:00
Erik Dubbelboer d64d07686a Prevent unnecessary logging during tests 2026-03-23 05:18:59 +01:00
Erik Dubbelboer d238e60fed Add ServeFileLiteral, ServeFSLiteral and SendFileLiteral (#2163)
ServeFile and ServeFS interpret the path as a URI, so percent-encoded
sequences are decoded and characters like '?' and '#' act as URI
delimiters. This makes it impossible to serve files whose names
contain those characters.

Changing this behavior would be backwards incompatible. So instead the
new ServeFileLiteral, ServeFSLiteral and SendFileLiteral are added.

The new Literal variants percent-encode the path before setting it as
the request URI, preserving every byte of the original filesystem path.

Thanks to @thesmartshadow for reporting this issue.
2026-03-23 03:21:36 +01:00
Erik Dubbelboer e2f8a255a0 Sanitize header values in all setter paths to prevent CRLF injection (#2162)
Prevents `header.Set("Key", "value\r\nEvil-Header: injected")` from
producing extra header lines in the HTTP response/request.

Thanks to @instantraaamen for reporting this issue.
2026-03-23 03:21:27 +01:00
Erik Dubbelboer 87f0fe1394 Update securego/gosec from 2.23.0 to 2.25.0 (#2161) 2026-03-20 07:27:24 +01:00
Erik Dubbelboer 4001e91911 Fix acquireRealZstdWriter panic
Pass the normalized compression level to prevent zstd.WithEncoderLevel
from returning an error.

Fixes https://github.com/valyala/fasthttp/issues/2157
2026-03-16 02:35:36 +01:00
Erik Dubbelboer 1ceb192a9b Remove stripTrailingSlashes
It was unused.
2026-03-16 02:30:39 +01:00
pj 6fcfcb1ac0 export ErrConnectionClosed (#2152) 2026-03-04 08:40:34 +09:00
dependabot[bot] bed2c19699 chore(deps): bump actions/upload-artifact from 6 to 7 (#2149)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-27 05:50:32 +01:00
Erik Dubbelboer 1d3c69196c Honor Root for fs.FS and normalize fs-style roots (#2145)
- Apply `fs.Root` in non-`os.FS` path resolution.
- Normalize `fs.FS` roots (`./`, trailing slash, leading slash, separators).
- Handle `PathRewrite` outputs without a leading slash.
- Add tests for `MapFS` and `DirFS` root enforcement.
2026-02-22 18:15:07 +01:00
Erik Dubbelboer f0d5d9a5cb Add WithLimit methods for uncompression (#2147)
* Add WithLimit methods for uncompression

The current uncompress methods don't enforce a memory limit and are
susceptible to things like zip bombs. This pull introduces new methods
so retain backwards compatibility. The old methods might be deprecated
in the future.

* Fix suggestion
2026-02-22 18:13:40 +01:00
Erik Dubbelboer c2b317d47d Go 1.26 and golangci-lint updates (#2146)
Keep Go 1.24 compatibility for now (by not using `wg.Go()`).
2026-02-21 10:28:39 +01:00
Erik Dubbelboer 80e3281747 fasthttpproxy: scope proxy auth cache to GetDialFunc (#2144)
Move auth cache from package-level to GetDialFunc lifetime to prevent
leaks.
2026-02-20 22:53:25 +01:00
dependabot[bot] a4ae8ef778 chore(deps): bump golang.org/x/net from 0.49.0 to 0.50.0 (#2138)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.49.0 to 0.50.0.
- [Commits](https://github.com/golang/net/compare/v0.49.0...v0.50.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.50.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-15 12:27:21 +01:00
dependabot[bot] 407041cba6 chore(deps): bump securego/gosec from 2.22.11 to 2.23.0 (#2142)
Bumps [securego/gosec](https://github.com/securego/gosec) from 2.22.11 to 2.23.0.
- [Release notes](https://github.com/securego/gosec/releases)
- [Commits](https://github.com/securego/gosec/compare/v2.22.11...v2.23.0)

---
updated-dependencies:
- dependency-name: securego/gosec
  dependency-version: 2.23.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-12 08:45:43 +01:00
dependabot[bot] 5002cc2c99 chore(deps): bump golang.org/x/crypto from 0.47.0 to 0.48.0 (#2139)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.47.0 to 0.48.0.
- [Commits](https://github.com/golang/crypto/compare/v0.47.0...v0.48.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.48.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-10 08:40:19 +01:00
dependabot[bot] 6a47a4c24d chore(deps): bump github.com/klauspost/compress from 1.18.3 to 1.18.4 (#2140)
Bumps [github.com/klauspost/compress](https://github.com/klauspost/compress) from 1.18.3 to 1.18.4.
- [Release notes](https://github.com/klauspost/compress/releases)
- [Commits](https://github.com/klauspost/compress/compare/v1.18.3...v1.18.4)

---
updated-dependencies:
- dependency-name: github.com/klauspost/compress
  dependency-version: 1.18.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-10 08:40:04 +01:00
dependabot[bot] 29c900bf8c chore(deps): bump golang.org/x/sys from 0.40.0 to 0.41.0 (#2137)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.40.0 to 0.41.0.
- [Commits](https://github.com/golang/sys/compare/v0.40.0...v0.41.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-version: 0.41.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-09 19:39:41 +01:00
Erik Dubbelboer 3471acf23f Limit url length in FuzzURIParse
We had fuzzers use urls of 500kb which doesn't make sense to test with.
2026-01-30 22:55:42 +01:00
dependabot[bot] 5fbda86a8e chore(deps): bump github.com/klauspost/compress from 1.18.2 to 1.18.3 (#2129)
Bumps [github.com/klauspost/compress](https://github.com/klauspost/compress) from 1.18.2 to 1.18.3.
- [Release notes](https://github.com/klauspost/compress/releases)
- [Commits](https://github.com/klauspost/compress/compare/v1.18.2...v1.18.3)

---
updated-dependencies:
- dependency-name: github.com/klauspost/compress
  dependency-version: 1.18.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-19 16:41:29 -03:00
dependabot[bot] a47d28f18f chore(deps): bump golang.org/x/net from 0.48.0 to 0.49.0 (#2128)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.48.0 to 0.49.0.
- [Commits](https://github.com/golang/net/compare/v0.48.0...v0.49.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.49.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-13 14:11:36 -03:00
dependabot[bot] 4df3fcd1fe chore(deps): bump golang.org/x/sys from 0.39.0 to 0.40.0 (#2125)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.39.0 to 0.40.0.
- [Commits](https://github.com/golang/sys/compare/v0.39.0...v0.40.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-version: 0.40.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-09 13:15:33 -05:00
pj 21dbfe80ce return prev values (#2123) 2026-01-07 18:13:11 -05:00