Skip to content

Fix Mihomo Hysteria2 Gecko obfs mapping - #194

Merged
kastov merged 2 commits into
remnawave:devfrom
Medium1992:fix-mihomo-hy2-gecko
Jul 7, 2026
Merged

Fix Mihomo Hysteria2 Gecko obfs mapping#194
kastov merged 2 commits into
remnawave:devfrom
Medium1992:fix-mihomo-hy2-gecko

Conversation

@Medium1992

Copy link
Copy Markdown
Contributor

Maps Hysteria2 finalmask packetSize obfs to Mihomo Gecko fields.

Keeps plain Salamander output unchanged when packetSize is not set.

@snyk-io

snyk-io Bot commented Jul 7, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@what-the-diff

what-the-diff Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Summary

  • Updated Interface Definition
    The structure of the Hysteria2FinalMask interface has been modified for improved flexibility. A new optional attribute, packetSize, has been added to the settings within the udp group.

  • Modified Data Handling Method
    The method responsible for data extraction, named buildHysteria2ObfsFields, has been enhanced to accommodate more data types. It's now able to handle both 'salamander' and 'gecko' types from the udp array and retrieves the related properties according to the updated structure.

  • Improved Decision-Making Process
    Changes have been introduced to the buildHysteria2ObfsFields method for better decision-making. It now includes additional conditions that handle the new packetSize settings. This enhancement allows the method to provide different output depending on the mask type and whether or not the packet size fields are present.

  • Created Dedicated Method for Packet Sizes
    With the addition of a new method, buildHysteria2PacketSizeFields, there's now a dedicated process for handling packetSize attributes. This method extracts and validates min and max packet sizes from the packetSize, and if they're acceptable, it presents these values in the required format.

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR extends buildHysteria2ObfsFields to recognise both salamander and gecko obfs types in the Hysteria2 finalmask, and adds a new buildHysteria2PacketSizeFields helper that parses a "min-max" range string into Mihomo's obfs-min-packet-size / obfs-max-packet-size fields.

  • When the source type is salamander and no packetSize is present the output is unchanged (obfs: salamander); otherwise the output is promoted to obfs: gecko with optional packet-size bounds.
  • The new buildHysteria2PacketSizeFields helper splits packetSize on - to extract min and max, guards against non-positive or non-finite values, and is a no-op when packetSize is absent.

Confidence Score: 3/5

The logic change is small and well-scoped but contains a TypeScript compile error that would break the build.

With strict: true and strictNullChecks: true in the project's tsconfig.json, accessing mask.type directly on a value typed T | undefined (returned by Array.find) is a compile-time error. The earlier if (!password) return {} guard makes the access safe at runtime, but TypeScript's control-flow analysis does not narrow mask through the optional-chaining read of password, so the build would fail until this is fixed.

src/modules/subscription-template/generators/mihomo.generator.service.ts — specifically the mask.type access on line 659 and the single-value packetSize parsing behaviour in buildHysteria2PacketSizeFields.

Important Files Changed

Filename Overview
src/modules/subscription-template/generators/mihomo.generator.service.ts Adds gecko obfs support and packet-size range parsing for Hysteria2 Mihomo output; contains a strictNullChecks compile error on mask.type and a minor ambiguity when packetSize is a plain number.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[buildHysteria2ObfsFields] --> B[Find udp entry: salamander or gecko]
    B --> C{mask found?}
    C -- no --> D[return empty]
    C -- yes --> E{password present?}
    E -- no --> D
    E -- yes --> F[buildHysteria2PacketSizeFields]
    F --> G{packetSize present?}
    G -- no --> H[packetSizeFields is empty]
    G -- yes --> I[split on dash, validate min and max]
    I --> J[populate packetSizeFields]
    H --> K{mask.type is salamander AND packetSizeFields empty?}
    J --> K
    K -- yes --> L[return obfs salamander]
    K -- no --> M[return obfs gecko plus packetSizeFields]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[buildHysteria2ObfsFields] --> B[Find udp entry: salamander or gecko]
    B --> C{mask found?}
    C -- no --> D[return empty]
    C -- yes --> E{password present?}
    E -- no --> D
    E -- yes --> F[buildHysteria2PacketSizeFields]
    F --> G{packetSize present?}
    G -- no --> H[packetSizeFields is empty]
    G -- yes --> I[split on dash, validate min and max]
    I --> J[populate packetSizeFields]
    H --> K{mask.type is salamander AND packetSizeFields empty?}
    J --> K
    K -- yes --> L[return obfs salamander]
    K -- no --> M[return obfs gecko plus packetSizeFields]
Loading

Reviews (1): Last reviewed commit: "fix: map hysteria2 gecko obfs for mihomo" | Re-trigger Greptile

Comment thread src/modules/subscription-template/generators/mihomo.generator.service.ts Outdated
Comment thread src/modules/subscription-template/generators/mihomo.generator.service.ts Outdated
@Medium1992
Medium1992 force-pushed the fix-mihomo-hy2-gecko branch from b23d7be to cd10550 Compare July 7, 2026 13:31
@kastov

kastov commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Можете уточнить, что это за параметры?
В оф. документации их не вижу: https://wiki.metacubex.one/config/proxies/hysteria2

@Medium1992

Medium1992 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Можете уточнить, что это за параметры? В оф. документации их не вижу: https://wiki.metacubex.one/config/proxies/hysteria2

https://github.com/MetaCubeX/mihomo/blob/5184081ac327394d9e15fa5d5f9f4a61e723fd94/docs/config.yaml#L1058
строки 1058-1061

Маленький тест уже провели, параметры передаются в yaml конфиге и hy2 в михомо с gecko начинает работать

Коммит
MetaCubeX/mihomo@f30a64f
Gecko есть в текущем stable mihomo

@spectreq666

Copy link
Copy Markdown

Тесты проводились с данным профилем ноды remnawave/templates#89

С вмонтированным генератором из PR Gecko корректно заработал на Mihomo

@kastov

kastov commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Тесты проводились с данным профилем ноды remnawave/templates#89

С вмонтированным генератором из PR Gecko корректно заработал на Mihomo

В нем же type: "salamander", а не "gecko".

@spectreq666

spectreq666 commented Jul 7, 2026

Copy link
Copy Markdown

Тесты проводились с данным профилем ноды remnawave/templates#89
С вмонтированным генератором из PR Gecko корректно заработал на Mihomo

В нем же type: "salamander", а не "gecko".

https://xtls.github.io/ru/config/transports/finalmask.html#gecko
Gecko - "надстройка" над Salamander, исходя из документации Xray
type: "gecko" не существует в реализации Xray, он начинает работать, когда указывается "packetSize"

@Medium1992

Medium1992 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Тесты проводились с данным профилем ноды remnawave/templates#89
С вмонтированным генератором из PR Gecko корректно заработал на Mihomo

В нем же type: "salamander", а не "gecko".

Работает только если указать gecko в mihomo
При указании salamander в mihomo, не учитываются поля min max

@spectreq666

spectreq666 commented Jul 7, 2026

Copy link
Copy Markdown

Тесты проводились с данным профилем ноды remnawave/templates#89
С вмонтированным генератором из PR Gecko корректно заработал на Mihomo

В нем же type: "salamander", а не "gecko".

Работает только если указать gecko При указании salamander в mihomo, не учитываются поля min max

Верно, в реализации Mihomo есть напрямую gecko.
у Xray ее нет.

@kastov
kastov merged commit 20ac2a5 into remnawave:dev Jul 7, 2026
1 check passed
kastov pushed a commit that referenced this pull request Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants