Commit Graph

1937 Commits

Author SHA1 Message Date
René db78ffe6f1 fix(prefork): tighten recovery callback flow 2026-05-02 12:12:45 +02:00
René b5233e2b48 test(prefork): isolate lifecycle tests 2026-04-29 11:05:22 +02:00
René ea7eb84217 fix(prefork): ensure recovery default stays positive 2026-04-29 11:00:32 +02:00
René eac6a01ef5 fix(prefork): avoid zombie processes and replace shallow tests
- Move Wait() goroutine before OnChildSpawn so Kill()+Wait() works
  correctly if a callback fails and the deferred cleanup runs
- Add Wait() call in deferred cleanup after Kill() to reap children
- Same fix in recovery loop
- Remove shallow callback tests that only tested Go compiler
- Add Test_Prefork_Lifecycle: runs full prefork with CommandProducer,
  verifies callbacks fire in correct order with correct arguments

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-29 09:04:23 +02:00
RW 07574a71d2 Merge branch 'master' into prefork_optimization 2026-04-26 17:43:18 +02:00
René fde83f8e3d refactor(prefork): address erikdubbelboer review feedback
- OnChildRecover: signature changed to func(oldPid, newPid int) so
  callers can track which process was replaced
- OnChildSpawn: also called for recovered children (a recovered child
  is still a spawned child)
- watchMaster: call OnMasterDeath when FindProcess fails (process is
  most likely gone)
- CommandProducer: document that FASTHTTP_PREFORK_CHILD=1 must be set
  in the child env, and what the default does when nil

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-25 12:36:02 +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
René 9758f93758 refactor(prefork): address maintainer review feedback
- watchMaster: log errors from FindProcess/Wait instead of swallowing
- watchMaster: don't call OnMasterDeath if FindProcess fails
- OnChildRecover: change signature to func(pid int), drop unused error return
- OnChildSpawn: add comment clarifying deferred cleanup handles the child
- CommandProducer: improve docs describing contract and use cases

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 09:30:30 +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
René be2ef67270 fix(prefork): address lint errors and review feedback
Lint fixes:
- Remove unused Reuseport field write in test (govet/unusedwrite)
- Replace fmt.Errorf with errors.New for static errors (perfsprint)

Review feedback (Copilot):
- Validate CommandProducer returns a started command (nil/Process check)
- Clarify ListenAndServeTLS doc: parameter order and internal forwarding
- Use hermetic test binary re-exec instead of external 'go' binary
- Rename misleading test to reflect what it actually asserts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 08:38:25 +02:00
René c1055ce62c fix(prefork): restore upstream ListenAndServeTLS parameter order
Keep upstream's (addr, certKey, certFile) signature to avoid breaking
callers. Fix the doc comment to match the actual parameter order instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 20:19:36 +02:00
René 2802b1a6a2 refactor(prefork): extract listenAsChild to eliminate DRY violation
The three ListenAndServe* methods had identical child setup code
(listen, set ln, watch master). Extract to listenAsChild() for
cleaner code. Also add comment for the magic file descriptor number 3.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 19:51:40 +02:00
René 768b8d66f1 fix(prefork): add Windows support to watchMaster
On Windows, os.Getppid() returns a static PID that doesn't change when
the parent exits (no reparenting). Use FindProcess+Wait instead, which
correctly detects parent exit. Also document why masterPID comparison
works for Docker containers (master PID 1 case).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 19:25:35 +02:00
René 6e448a0683 merge upstream/master and resolve prefork conflicts
Integrate upstream's OnMasterDeath callback (replaces WatchMaster bool),
os.Executable() for child command, and watchMaster as method on Prefork.
Keep our OnChildSpawn, OnMasterReady, OnChildRecover callbacks and
CommandProducer. Update tests accordingly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 19:20:54 +02: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
René 72a6256ff4 refactor(prefork): enhance logging message and clarify OnChildRecover callback comment 2026-02-06 09:44:26 +01:00
René 94d5cc6b65 refactor(prefork): improve comments and parameter order in ListenAndServeTLS 2026-02-06 09:37:43 +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
René 81e8463a27 feat(prefork): add CommandProducer for customizable child process commands 2026-01-28 13:09:03 +01:00