Conversation
fix: 修复响应URL生成逻辑
There was a problem hiding this comment.
Pull request overview
This PR adds server-side support for XHTTP obfs padding by detecting padding markers on incoming requests, validating padding using HPACK Huffman encoded length checks (tokenish), and applying randomized padding to responses. It also updates xhttp node configuration generation to include the required obfs padding parameters in the extra field.
Changes:
- Added XHTTP obfs padding extraction, HPACK Huffman length calculation, validation, and response padding generation in
_worker.js. - Enhanced XHTTP request detection to also recognize padding headers and query parameters.
- Updated protocol configuration generation for xhttp nodes to inject
xPaddingObfsMode-related parameters; updatedCHANGELOG.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| CHANGELOG | Documents the new XHTTP obfs padding receiver support and version entry. |
| _worker.js | Implements padding extraction/validation/response padding for XHTTP and injects xhttp extra parameters during config generation. |
Suppressed comments (2)
_worker.js:4713
获取传输协议配置(配置 = {})现在无条件调用获取XHTTPPadding标识(配置.UUID),这会让该函数在UUID缺失/非字符串时直接抛错(与默认参数{}的可选性不匹配),并且在非 xhttp 协议下做了不必要的计算。建议仅在传输协议 === 'xhttp'且UUID合法时生成 padding 标识,并用encodeURIComponent(JSON.stringify(...))生成extra,避免手写 URL 编码字符串。
function 获取传输协议配置(配置 = {}) {
const 是gRPC = 配置.传输协议 === 'grpc';
const { 头: 本机Padding头, 键: 本机Padding键 } = 获取XHTTPPadding标识(配置.UUID);
return {
type: 是gRPC ? (配置.gRPC模式 === 'multi' ? 'grpc&mode=multi' : 'grpc&mode=gun') : (配置.传输协议 === 'xhttp' ? `xhttp&mode=stream-one&extra=%7B%22xPaddingObfsMode%22%3Atrue%2C%22xPaddingMethod%22%3A%22tokenish%22%2C%22xPaddingPlacement%22%3A%22queryInHeader%22%2C%22xPaddingHeader%22%3A%22${本机Padding头}%22%2C%22xPaddingKey%22%3A%22${本机Padding键}%22%7D` : 'ws'),
路径字段名: 是gRPC ? 'serviceName' : 'path',
_worker.js:610
生成XHTTPPadding串使用Math.random()生成 padding,会带来可预测性且与文件内其他随机字节生成方式(多处使用crypto.getRandomValues)不一致。建议改为基于crypto.getRandomValues生成随机字节再映射到 base62 字符集。
function 生成XHTTPPadding串(长度) {
const 字符集长度 = XHTTPBase62字符集.length;
let 结果 = '';
for (let i = 0; i < 长度; i++) {
结果 += XHTTPBase62字符集[Math.floor(Math.random() * 字符集长度)];
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+74
to
+77
| const { 头: 本机Padding头, 键: 本机Padding键 } = 获取XHTTPPadding标识(userID); | ||
| const 命中XHTTP特征 = referer.includes('x_padding', 14) || referer.includes('x_padding=') | ||
| || !!request.headers.get(本机Padding头) | ||
| || !!url.searchParams.get(本机Padding键); |
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.
This pull request adds support for XHTTP obfs padding (obfuscation padding) on the server side, enabling the system to recognize and validate special padding headers and query parameters for enhanced protocol camouflage. It introduces the ability to extract, validate, and generate obfs padding according to the "tokenish" and "queryInHeader" modes, aligning with upstream implementations. The changes also update the protocol configuration and response handling to support these features.
XHTTP obfs padding support:
处理XHTTP请求) to perform obfs padding extraction and validation, rejecting requests with invalid padding.Protocol configuration and detection:
获取传输协议配置) to inject XHTTP obfs padding parameters into theextrafield for xhttp nodes, ensuring clients send the correct padding.Documentation and versioning:
CHANGELOGto document the addition of XHTTP obfs padding receiver support.2026-08-10 03:09:01.