Skip to content

Panic in ProcessNameMatcher when source IPs are empty #5573

@KiGamji

Description

@KiGamji

Integrity requirements

  • I have read all the comments in the issue template and ensured that this issue meet the requirements.
  • I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • I searched issues and did not find any similar issues.
  • The problem can be successfully reproduced in the latest Release

Description

Xray-core panics with index out of range [0] with length 0 when a routing rule using processName matching is evaluated but the routing context has no source IPs available.

The crash occurs in app/router/condition.go line 362:

srcIP := ctx.GetSourceIPs()[0].String()

This line accesses index [0] without checking if the slice is empty. GetSourceIPs() can return nil when the inbound source is not valid or not an IP address.

Reproduction Method

The crash occurred when using process name based routing rules. The specific trigger appears to be an internal API connection (127.0.0.1 -> api), but any scenario where the routing context lacks source IP information would trigger this.

I was able to trigger this by adding a process name in v2rayN's routing settings, and then enabling the TUN mode... I think it's not properly implemented on their side yet 😅

Suggested Fix:

Add a length check before accessing the slice:

srcIPs := ctx.GetSourceIPs()
if len(srcIPs) == 0 {
    return false
}
srcIP := srcIPs[0].String()

Version: 26.1.18

Client log

2026/01/19 18:39:48.480967 [Warning] core: Xray 26.1.18 started
2026/01/19 18:39:48.554417 from 127.0.0.1:59993 accepted tcp:127.0.0.1:10812 [api -> api]
panic: runtime error: index out of range [0] with length 0
goroutine 100 [running]:
github.com/xtls/xray-core/app/router.(*ProcessNameMatcher).Apply(0xc006a26e60, {0x7ff709174140, 0xc0020424e0})
  github.com/xtls/xray-core/app/router/condition.go:362 +0x574
github.com/xtls/xray-core/app/router.(*ConditionChan).Apply(0x18?, {0x7ff709174140, 0xc0020424e0})
  github.com/xtls/xray-core/app/router/condition.go:36 +0x5c
github.com/xtls/xray-core/app/router.(*Rule).Apply(...)
  github.com/xtls/xray-core/app/router/config.go:29
github.com/xtls/xray-core/app/router.(*Router).pickRouteInternal(0xc000317ab0, {0x7ff709174140, 0xc0020424e0})
  github.com/xtls/xray-core/app/router/router.go:195 +0x16b
github.com/xtls/xray-core/app/router.(*Router).PickRoute(0xc00025d5c0?, {0x7ff709174140?, 0xc0020424e0?})
  github.com/xtls/xray-core/app/router/router.go:83 +0x25
github.com/xtls/xray-core/app/dispatcher.(*DefaultDispatcher).routedDispatch(0xc000187c20, {0x7ff709164eb0, 0xc00025d5c0}, 0xc0071fc280, {{0x7ff709164f90, 0xc0073140d0}, 0x1bb, 0x2})
  github.com/xtls/xray-core/app/dispatcher/default.go:475 +0x1c8
created by github.com/xtls/xray-core/app/dispatcher.(*DefaultDispatcher).Dispatch in goroutine 29
  github.com/xtls/xray-core/app/dispatcher/default.go:307 +0x686
2026.01.19 18:39:54 The delay: -1 ms, none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions