Commit Graph

69 Commits

Author SHA1 Message Date
ginuerzh 1b07475bf3 feat(forwarder): support plugin-based rewriter in HTTP body rewrite rules
Each rewriteBody/rewriteResponseBody/rewriteRequestBody rule can now
optionally reference a named rewriter plugin (HTTP/gRPC backend) via
the rewriter field. When set, body rewriting delegates to the plugin
rather than applying pattern/replacement, while content-type filtering
still applies.

Coincident fixes:
- rewriter/plugin/grpc: return nil when conn is nil (avoid nil-ptr panic)
- rewriter/plugin/http: drain response body in defer to prevent leaks
- config/parsing/rewriter: pass TimeoutOption to gRPC plugin
- config/parsing/service: warn when referenced rewriter is not registered
2026-06-27 22:52:17 +08:00
ginuerzh 3b25e0317f feat(rewriter): implement plugin-based Rewriter module with gRPC and HTTP backends
Add the first implementation of core/rewriter.Rewriter as a plugin-only
component following the bypass/admission pattern (single-value, no
RewriterObject). Includes:

- plugin/rewriter/proto/: protobuf definition with Rewrite RPC returning
  transformed data in the reply
- x/rewriter/plugin/: gRPC and HTTP plugin clients
- x/registry/rewriter.go: hot-reload-safe RewriterRegistry with wrapper
- x/config/config.go: RewriterConfig, Config.Rewriters, ServiceConfig.Rewriter
- x/config/parsing/rewriter/parse.go: config parser (plugin backends only)
- core/handler/option.go: Rewriter field + RewriterOption on handler.Options
- x/config/loader/loader.go: rewriter registration during startup
- x/config/parsing/service/parse.go: inject rewriter into handler options
2026-06-27 21:44:13 +08:00
ginuerzh cd97e5e746 fix(hop): skip priority short-circuit when multiple nodes share the same priority
When two or more nodes have an identical matcher rule they receive
identical default priority (rule string length). The priority shortcut
assumed the top-priority node was the single authoritative choice and
returned it directly, bypassing the selector (FailFilter, BackupFilter,
strategy) — so weight, round-robin, and hash were silently ignored.

Add a third condition: the top priority must be strictly greater than
the second-highest. When multiple nodes share the same highest priority
the selector applies normally for load balancing.

Add doc comments on NodeMatcherConfig.Priority explaining the three
semantic ranges (0=auto, negative=always-selector, positive=shortcut).
2026-06-26 22:53:17 +08:00
ginuerzh e583f5b538 feat(parser): support HTTP(S) URL config sources with -C flag
Add remote config fetching capability to the -C CLI flag, enabling
centralized fleet management of gost nodes.

- readConfig() now detects http:// and https:// URLs and fetches
  them via HTTP GET with a 30s timeout and shared client pool
- Format auto-detection from Content-Type header (using mime
  parsing) with fallback to URL path extension (.yaml/.json)
- 10 MiB response size limit to prevent memory exhaustion
- URL userinfo stripped from error messages for safety
- Fix ReadFile to force viper config type from file extension,
  preventing format detection ambiguity
- Fix viper config search path fallback: skip cfg.Load() when
  -C flags are explicitly provided, avoiding unwanted merges
- Tests: URL fetch (YAML/JSON), non-200, oversize, detectFormat,
  isHTTPURL, sanitizeURL, and combined file+URL Parse scenario
2026-06-20 20:11:43 +08:00
Usishchev Yury b23553d37a feat: add quota limiter and quota API (#107) 2026-06-20 14:44:42 +08:00
Kebin Liu eaeac2763e Bypass with network (#101)
* Fix logger init before use it

* Support specific network protocol validation in bypass
2026-06-13 12:36:09 +08:00
ginuerzh dd19e4387a feat(tls): add rejectUnknownSNI support for TLS listeners
Adds RejectUnknownSNI and ServerNames fields to TLSConfig. When enabled,
TLS handshakes with missing or non-allowlisted SNI are rejected at the
handshake level via GetConfigForClient before any certificate is sent.

Works across all TLS-based listener types (tls, mtls, ws, mws, http2,
grpc, http3) since they share the same *tls.Config from LoadServerConfig.
2026-05-31 22:11:29 +08:00
ginuerzh cf89192211 feat(forwarder/sniffer): add HTTP request body rewriting, deprecate rewriteBody in favor of rewriteResponseBody
- Add RewriteRequestBody field to HTTPNodeConfig (yaml: rewriteRequestBody)
- Add RewriteRequestBody field to HTTPNodeSettings in core chain
- Add rewriteReqBody function symmetric to rewriteRespBody in sniffer_rewrite.go
- Wire up rewriteReqBody call in httpRoundTrip before body wrapping for recording
- Add new RewriteResponseBody config field, deprecate old RewriteBody
- Parse both RewriteRequestBody and RewriteResponseBody in node config parsing
- Add 10 test cases covering nil, skip, content-type filter, and chained rewrites
- Bump core dependency to v0.4.1
- Fix: clone response header map in internal/util/sniffing/sniffer_http.go
2026-05-31 19:46:41 +08:00
ginuerzh f71351f5ef add interface xnet.SrcAddr/DstAddr 2025-08-03 10:15:53 +08:00
ginuerzh c8d905dea5 read config from stdin 2025-06-28 18:09:04 +08:00
ginuerzh 6caad5e37e add file option for AuthConfig 2025-06-24 21:16:17 +08:00
Denis Galeev e4b1c3c2b5 feat recorder: add rotate options 2025-02-18 15:30:42 +08:00
ginuerzh 355c72477a add router handler & connector 2025-02-07 15:44:31 +08:00
ginuerzh 6f001a779a tunnel: fix tunnel routing for public entrypoint 2024-11-22 22:04:44 +08:00
ginuerzh 2e8a5d6f51 fix http keepalive for forwarding 2024-11-17 16:16:20 +08:00
ginuerzh c2aedbabd9 add routing rule for node 2024-11-15 20:28:47 +08:00
ginuerzh 3db20563d2 add custom http response header for reverse proxy 2024-11-07 11:04:42 +08:00
ginuerzh dfb6cb95d0 add username for redis 2024-09-25 22:05:19 +08:00
ginuerzh e22aa91571 add route for recorder 2024-09-24 20:20:15 +08:00
ginuerzh 69455ace9d add handler recorder 2024-09-14 23:21:25 +08:00
ginuerzh 3656ba9315 add http body rewrite for forward handler 2024-07-19 20:45:04 +08:00
ginuerzh 2ae0462822 add support for linux network namespace 2024-06-21 23:38:18 +08:00
ginuerzh 118ee91c95 fix error response for web APIs 2024-06-04 22:05:13 +08:00
ginuerzh 40f709880d add node filter config 2024-05-08 21:25:14 +08:00
ginuerzh 25dcf536c6 added url path rewrite for forwarder node 2024-01-31 23:18:42 +08:00
ginuerzh 8bdd7ee172 added auther option for node http settings 2024-01-27 21:29:45 +08:00
ginuerzh 01168e9846 fix deadlock in websocket client conn 2024-01-12 23:46:22 +08:00
ginuerzh c959fc2f73 add observer 2024-01-03 20:55:06 +08:00
ginuerzh 4a1b225d2c add logger group for service 2023-12-19 21:28:19 +08:00
ginuerzh c87faa2017 add logger component 2023-11-19 19:55:48 +08:00
ginuerzh 74639e9c4e add router component 2023-11-19 14:23:21 +08:00
ginuerzh 88cc6ff4d5 add traffic limiter for proxy handler 2023-11-18 18:28:09 +08:00
ginuerzh 6bface4581 add path option for hop 2023-11-09 20:34:59 +08:00
ginuerzh a697bf2e35 update resolver 2023-11-08 20:51:43 +08:00
ginuerzh a7166b8206 add sd for tunnel 2023-10-31 22:59:14 +08:00
ginuerzh e8d5e719a4 add tls options 2023-10-29 10:27:13 +08:00
ginuerzh 4be7d60147 add auther for metrics 2023-10-09 21:27:35 +08:00
ginuerzh ea585fc25d add reload and plugin support for hop 2023-09-28 21:04:15 +08:00
ginuerzh 1760151500 add HTTP plugin 2023-09-20 22:56:43 +08:00
ginuerzh a743862f23 add recorder for serial handler 2023-09-18 21:13:11 +08:00
ginuerzh 73b563f0c1 add token for plugin 2023-04-20 19:05:59 +08:00
ginuerzh 32c8188351 add plugin system 2023-04-18 20:52:56 +08:00
ginuerzh ebdb77d71f add auth support for forwarder node 2023-01-31 14:04:28 +08:00
ginuerzh 66234239e4 add http node settings 2023-01-29 20:31:13 +08:00
ginuerzh 93b40f4c86 fix race condition in config updating 2023-01-20 10:27:21 +08:00
ginuerzh 82cd924c86 add tunnel feature for relay 2023-01-14 13:15:15 +08:00
ginuerzh 9b128534a0 case-insensitive metadata key 2023-01-11 22:25:58 +08:00
ginuerzh 2e89811d59 sniffing protocol for port forwarding 2022-11-30 10:54:19 +08:00
ginuerzh 1ff2bab1f0 add vhost for port forwarding 2022-11-11 22:23:36 +08:00
ginuerzh 15d0a33716 add log rotation config 2022-10-20 15:32:27 +08:00