{"record":{"id":"4610f407aa808e37","repo":"projectdiscovery/katana","slug":"hijack-pattern-not-set","errorCode":null,"errorMessage":"hijack pattern not set","messagePattern":"hijack pattern not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/engine/hybrid/hijack.go","lineNumber":39,"sourceCode":"// Hijack is a hijack handler\ntype Hijack struct {\n\tpage    *rod.Page\n\tenable  *proto.FetchEnable\n\tdisable *proto.FetchDisable\n\tcancel  func()\n}\n\n// SetPattern set pattern directly\nfunc (h *Hijack) SetPattern(pattern *proto.FetchRequestPattern) {\n\th.enable = &proto.FetchEnable{\n\t\tPatterns: []*proto.FetchRequestPattern{pattern},\n\t}\n}\n\n// Start hijack.\nfunc (h *Hijack) Start(handler HijackHandler) func() error {\n\tif h.enable == nil {\n\t\tpanic(\"hijack pattern not set\")\n\t}\n\n\tp, cancel := h.page.WithCancel()\n\th.cancel = cancel\n\n\terr := h.enable.Call(p)\n\tif err != nil {\n\t\treturn func() error { return err }\n\t}\n\n\twait := p.EachEvent(func(e *proto.FetchRequestPaused) {\n\t\tif handler != nil {\n\t\t\terr = handler(e)\n\t\t}\n\t})\n\n\treturn func() error {\n\t\twait()","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/engine/hybrid/hijack.go#L21-L57","documentation":"Hijack.Start panics with \"hijack pattern not set\" when h.enable is nil, meaning Hijack.Enable (or the pattern-configuring method) was never called before Start. The library treats this as a programming error: you cannot start intercepting requests without first specifying which URL pattern to hijack. It is a panic, not a returned error, so it must be prevented by correct setup order.","triggerScenarios":"Calling hijack.Start(handler) directly on a zero-value or freshly constructed Hijack struct; calling Start before Enable/pattern configuration; constructing Hijack manually instead of through the helper that sets the pattern.","commonSituations":"Refactoring moved the Enable call after Start; copying Hijack struct code without initializing the enable field; using the hijack API in a custom navigation flow (navigateRequest path) without the standard setup.","solutions":["Call hijack.Enable/with the desired URL pattern before invoking Start.","Ensure the Hijack value is created through the library's constructor/helper that initializes the enable field, not as a zero-value struct literal.","In code paths like navigateRequest, verify the pattern is configured before starting the hijack.","Guard the call site with a nil check or recover() if the hijack setup is conditional."],"exampleFix":"// before\nh := &Hijack{page: page}\nh.Start(handler) // panics: pattern never set\n// after\nh := &Hijack{page: page}\nh.Enable(\"**/api/**\") // set the hijack pattern first\nh.Start(handler)","handlingStrategy":"validation","validationCode":"// ensure the hijack is configured before starting\n// (h.enable is internal; enforce ordering in your wrapper)\nfunc startHijack(h *engine.Hijack, pattern string, handler engine.HijackHandler) (func() error, error) {\n    if h == nil {\n        return nil, errors.New(\"nil hijack\")\n    }\n    h.Enable(pattern) // MUST precede Start\n    return h.Start(handler), nil\n}","typeGuard":null,"tryCatchPattern":"// Go: it panics — wrap setup in recover during development\nfunc safeStart(h *Hijack, handler HijackHandler) (stop func() error, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"hijack start: %v\", r)\n        }\n    }()\n    return h.Start(handler), nil\n}","preventionTips":["Always call Enable/with-pattern before Start; never use a zero-value Hijack struct.","Construct Hijack through the library helper that sets the pattern.","In navigateRequest-style flows, assert the pattern is configured in tests."],"tags":["network","hijack","misconfiguration"],"backgroundTag":"hijack-pattern-not-set","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}