Repository navigation
feat: 支持基于Go Regex规则和全量的请求体透传 - #2840
Conversation
WalkthroughThis PR introduces a header passthrough feature for API request handling. The backend adds wildcard and regex-based passthrough rules with a skip-list for unsafe headers, while the frontend provides UI templates for configuration. Translations are added across six languages to support the new passthrough template labels. Changes
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@relay/channel/api_request.go`:
- Around line 50-74: The passthrough skip list currently omits the cookie
header; update the map variable passthroughSkipHeaderNamesLower in
relay/channel/api_request.go (the map literal containing RFC 7230 hop-by-hop and
other sensitive headers) to include "cookie": {} so request cookies are not
forwarded by wildcard/regex passthrough rules; also add or adjust unit tests
that assert sensitive headers are blocked if such tests exist.
In `@web/src/components/table/channels/modals/EditChannelModal.jsx`:
- Around line 3116-3154: The first clickable Text in EditChannelModal.jsx that
fills the full passthrough template currently uses t('填入模板'); update that label
to the new i18n key t('填入透传完整模版') so the full passthrough template uses the
correct translation; the change should be made on the Text component that calls
handleInputChange('header_override', JSON.stringify({ '*': true,
're:^X-Trace-.*$': true, ... }, null, 2)) to keep the other passthrough Text
(which uses t('填入透传模版')) unchanged.
In `@web/src/i18n/locales/zh.json`:
- Around line 738-739: Update the Chinese display values for the keys "填入透传模版"
and "填入透传完整模版" in zh.json to use the consistent character "模板" instead of "模版"
(keys can remain unchanged); change the value strings to "填入透传模板" and "填入透传完整模板"
respectively so they match nearby UI text.
🧹 Nitpick comments (2)
web/src/i18n/locales/ru.json (1)
753-754: Align “passthrough” terminology with existing Russian translations.These two strings use English “passthrough,” while other “透传” entries are translated into Russian (e.g., “прозрачная/прямая передача”). Consider standardizing terminology for consistency across the UI.
💡 Possible wording (example)
- "填入透传模版": "Заполнить шаблон passthrough", - "填入透传完整模版": "Заполнить полный шаблон passthrough", + "填入透传模版": "Заполнить шаблон сквозной передачи", + "填入透传完整模版": "Заполнить полный шаблон сквозной передачи",relay/channel/api_request.go (1)
76-98: Unbounded regex cache may cause memory growth.The
sync.Mapcache stores compiled regexes indefinitely with no eviction. In long-running deployments where channel configurations change frequently or many unique patterns are used, this could lead to gradual memory growth.For now this is likely acceptable if patterns are admin-controlled and relatively static, but consider adding a bounded cache (e.g., LRU with a size limit) if memory becomes a concern in production.
| var passthroughSkipHeaderNamesLower = map[string]struct{}{ | ||
| // RFC 7230 hop-by-hop headers. | ||
| "connection": {}, | ||
| "keep-alive": {}, | ||
| "proxy-authenticate": {}, | ||
| "proxy-authorization": {}, | ||
| "te": {}, | ||
| "trailer": {}, | ||
| "transfer-encoding": {}, | ||
| "upgrade": {}, | ||
|
|
||
| // Additional headers that should not be forwarded by name-matching passthrough rules. | ||
| "host": {}, | ||
| "content-length": {}, | ||
|
|
||
| // Do not passthrough credentials by wildcard/regex. | ||
| "authorization": {}, | ||
| "x-api-key": {}, | ||
| "x-goog-api-key": {}, | ||
|
|
||
| // WebSocket handshake headers are generated by the client/dialer. | ||
| "sec-websocket-key": {}, | ||
| "sec-websocket-version": {}, | ||
| "sec-websocket-extensions": {}, | ||
| } |
There was a problem hiding this comment.
Consider adding cookie to the skip list.
The cookie header often contains session tokens and authentication data. With wildcard (*) or broad regex passthrough, cookies could be unintentionally forwarded to upstream services, potentially leaking user sessions.
If cookie passthrough is intentionally supported, this is fine—but please confirm this is the desired behavior.
🛡️ Proposed fix to block cookie passthrough
// Do not passthrough credentials by wildcard/regex.
"authorization": {},
"x-api-key": {},
"x-goog-api-key": {},
+ "cookie": {},
// WebSocket handshake headers are generated by the client/dialer.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var passthroughSkipHeaderNamesLower = map[string]struct{}{ | |
| // RFC 7230 hop-by-hop headers. | |
| "connection": {}, | |
| "keep-alive": {}, | |
| "proxy-authenticate": {}, | |
| "proxy-authorization": {}, | |
| "te": {}, | |
| "trailer": {}, | |
| "transfer-encoding": {}, | |
| "upgrade": {}, | |
| // Additional headers that should not be forwarded by name-matching passthrough rules. | |
| "host": {}, | |
| "content-length": {}, | |
| // Do not passthrough credentials by wildcard/regex. | |
| "authorization": {}, | |
| "x-api-key": {}, | |
| "x-goog-api-key": {}, | |
| // WebSocket handshake headers are generated by the client/dialer. | |
| "sec-websocket-key": {}, | |
| "sec-websocket-version": {}, | |
| "sec-websocket-extensions": {}, | |
| } | |
| var passthroughSkipHeaderNamesLower = map[string]struct{}{ | |
| // RFC 7230 hop-by-hop headers. | |
| "connection": {}, | |
| "keep-alive": {}, | |
| "proxy-authenticate": {}, | |
| "proxy-authorization": {}, | |
| "te": {}, | |
| "trailer": {}, | |
| "transfer-encoding": {}, | |
| "upgrade": {}, | |
| // Additional headers that should not be forwarded by name-matching passthrough rules. | |
| "host": {}, | |
| "content-length": {}, | |
| // Do not passthrough credentials by wildcard/regex. | |
| "authorization": {}, | |
| "x-api-key": {}, | |
| "x-goog-api-key": {}, | |
| "cookie": {}, | |
| // WebSocket handshake headers are generated by the client/dialer. | |
| "sec-websocket-key": {}, | |
| "sec-websocket-version": {}, | |
| "sec-websocket-extensions": {}, | |
| } |
🤖 Prompt for AI Agents
In `@relay/channel/api_request.go` around lines 50 - 74, The passthrough skip list
currently omits the cookie header; update the map variable
passthroughSkipHeaderNamesLower in relay/channel/api_request.go (the map literal
containing RFC 7230 hop-by-hop and other sensitive headers) to include "cookie":
{} so request cookies are not forwarded by wildcard/regex passthrough rules;
also add or adjust unit tests that assert sensitive headers are blocked if such
tests exist.
| <Text | ||
| className='!text-semi-color-primary cursor-pointer' | ||
| onClick={() => | ||
| handleInputChange( | ||
| 'header_override', | ||
| JSON.stringify( | ||
| { | ||
| '*': true, | ||
| 're:^X-Trace-.*$': true, | ||
| 'X-Foo': '{client_header:X-Foo}', | ||
| Authorization: 'Bearer {api_key}', | ||
| 'User-Agent': | ||
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0', | ||
| }, | ||
| null, | ||
| 2, | ||
| ), | ||
| ) | ||
| } | ||
| > | ||
| {t('填入模板')} | ||
| </Text> | ||
| <Text | ||
| className='!text-semi-color-primary cursor-pointer' | ||
| onClick={() => | ||
| handleInputChange( | ||
| 'header_override', | ||
| JSON.stringify( | ||
| { | ||
| 'User-Agent': | ||
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0', | ||
| Authorization: 'Bearer{api_key}', | ||
| '*': true, | ||
| }, | ||
| null, | ||
| 2, | ||
| ), | ||
| ) | ||
| } | ||
| > | ||
| {t('填入模板')} | ||
| {t('填入透传模版')} | ||
| </Text> |
There was a problem hiding this comment.
Align the full passthrough template label with the new i18n key.
The full template still shows “填入模板”, while translations include “填入透传完整模版”. This makes the UI ambiguous and leaves the new key unused.
💡 Suggested label fix
- {t('填入模板')}
+ {t('填入透传完整模版')}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <Text | |
| className='!text-semi-color-primary cursor-pointer' | |
| onClick={() => | |
| handleInputChange( | |
| 'header_override', | |
| JSON.stringify( | |
| { | |
| '*': true, | |
| 're:^X-Trace-.*$': true, | |
| 'X-Foo': '{client_header:X-Foo}', | |
| Authorization: 'Bearer {api_key}', | |
| 'User-Agent': | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0', | |
| }, | |
| null, | |
| 2, | |
| ), | |
| ) | |
| } | |
| > | |
| {t('填入模板')} | |
| </Text> | |
| <Text | |
| className='!text-semi-color-primary cursor-pointer' | |
| onClick={() => | |
| handleInputChange( | |
| 'header_override', | |
| JSON.stringify( | |
| { | |
| 'User-Agent': | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0', | |
| Authorization: 'Bearer{api_key}', | |
| '*': true, | |
| }, | |
| null, | |
| 2, | |
| ), | |
| ) | |
| } | |
| > | |
| {t('填入模板')} | |
| {t('填入透传模版')} | |
| </Text> | |
| <Text | |
| className='!text-semi-color-primary cursor-pointer' | |
| onClick={() => | |
| handleInputChange( | |
| 'header_override', | |
| JSON.stringify( | |
| { | |
| '*': true, | |
| 're:^X-Trace-.*$': true, | |
| 'X-Foo': '{client_header:X-Foo}', | |
| Authorization: 'Bearer {api_key}', | |
| 'User-Agent': | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0', | |
| }, | |
| null, | |
| 2, | |
| ), | |
| ) | |
| } | |
| > | |
| {t('填入透传完整模版')} | |
| </Text> | |
| <Text | |
| className='!text-semi-color-primary cursor-pointer' | |
| onClick={() => | |
| handleInputChange( | |
| 'header_override', | |
| JSON.stringify( | |
| { | |
| '*': true, | |
| }, | |
| null, | |
| 2, | |
| ), | |
| ) | |
| } | |
| > | |
| {t('填入透传模版')} | |
| </Text> |
🤖 Prompt for AI Agents
In `@web/src/components/table/channels/modals/EditChannelModal.jsx` around lines
3116 - 3154, The first clickable Text in EditChannelModal.jsx that fills the
full passthrough template currently uses t('填入模板'); update that label to the new
i18n key t('填入透传完整模版') so the full passthrough template uses the correct
translation; the change should be made on the Text component that calls
handleInputChange('header_override', JSON.stringify({ '*': true,
're:^X-Trace-.*$': true, ... }, null, 2)) to keep the other passthrough Text
(which uses t('填入透传模版')) unchanged.
| "填入透传模版": "填入透传模版", | ||
| "填入透传完整模版": "填入透传完整模版", |
There was a problem hiding this comment.
Use “模板” in the Chinese display text for consistency.
These two labels use “模版” while nearby UI uses “模板”. Consider updating the values to “模板” (keys can remain unchanged if already referenced elsewhere).
✏️ Suggested change
- "填入透传模版": "填入透传模版",
- "填入透传完整模版": "填入透传完整模版",
+ "填入透传模版": "填入透传模板",
+ "填入透传完整模版": "填入透传完整模板",📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "填入透传模版": "填入透传模版", | |
| "填入透传完整模版": "填入透传完整模版", | |
| "填入透传模版": "填入透传模板", | |
| "填入透传完整模版": "填入透传完整模板", |
🤖 Prompt for AI Agents
In `@web/src/i18n/locales/zh.json` around lines 738 - 739, Update the Chinese
display values for the keys "填入透传模版" and "填入透传完整模版" in zh.json to use the
consistent character "模板" instead of "模版" (keys can remain unchanged); change
the value strings to "填入透传模板" and "填入透传完整模板" respectively so they match nearby
UI text.
…x-override feat: 支持基于Go Regex规则和全量的请求体透传
…x-override feat: 支持基于Go Regex规则和全量的请求体透传
…x-override feat: 支持基于Go Regex规则和全量的请求体透传
功能位置:渠道编辑-请求头覆盖
Summary by CodeRabbit
Release Notes