fix(clustering): updated cluster failure handling#6843
fix(clustering): updated cluster failure handling#6843ehsandeep merged 3 commits intoprojectdiscovery:devfrom
Conversation
WalkthroughAdds matcher-status error reporting across many protocols and cluster/template execution: emits structured callback events on error paths and generates synthetic failure events when per-operator callbacks were not invoked; also adds an integration test validating matcher-status for clustered templates with AND-condition matchers. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
|
I thought I fixed the change that is erroring; I'm investigating. |
|
Okay, I reverted the call backs; but my fix for the clustered output is still valid. |
|
The failing integration test is flaky and doesn't seem to be related to this change at all. |
Thank you! Is there anything else you need from me to get this over the finish line? |
|
@dwisiswant0 good afternoon! Sorry for the ping. I just wanted to checkin on this one. Is it waiting on something from me? |
|
Good afternoon, @dogancanbakir! I just wanted to check in on this ask 😄. |
ehsandeep
left a comment
There was a problem hiding this comment.
@bf-rbrown apologies for the delay, and thanks for helping improve this feature.
Proposed changes
Summary
This fixes #6842
-matcher-statusnot printing[failed]output for clustered templates that usematchers-condition: andClusterExecuterthat already existed inTemplateExecuterRoot Cause
Two issues combined to cause this:
1.
ClusterExecuterfailure condition too strict (pkg/templates/cluster.go)The condition for writing failure events was
result == nil && !matched. Whenmatchers-condition: andis used and any matcher fails,operators.Execute()returns early with a non-nilResultstruct butmatched=false. Sinceresultwas non-nil, the nil check failed and the failure was silently dropped. Formatchers-condition: or(default),operators.Execute()returnsnilon failure, so failures were reported correctly. The fix relaxes the condition to only check!matched.2. Protocol error paths not invoking the callback
When a protocol request fails early (connection error, validation error, etc.), most implementations returned an error without invoking the
callback. This meant the executor had no event to report as[failed]. Added callback invocations on error paths across all protocols. For HTTP specifically, the error path previously only invoked the callback when interactsh (OOB) URLs were present -- to register the request for later OOB correlation. Since the fix requires the callback to always fire on error regardless of interactsh usage, the interactsh-specific gating was removed.Synthetic Failure Events
TemplateExecuteralready had a fallback that synthesized a fake failure event when no callback was received. Two improvements were made to it:Enriched the existing fake event in
TemplateExecuter(pkg/tmplexec/exec.go): The original event only setTemplateID,Info,Type,Host, andError. TheHostfield was set to the raw input string (e.g.https://example.com:443), which could produce malformed output. Now usesGetJsonFieldsFromURLto properly parse the input and populateHost,Port,Scheme,URL,Path,TemplatePath, andTimestamp.Added equivalent fallback to
ClusterExecuter(pkg/templates/cluster.go):ClusterExecuterhad no fallback at all -- if the callback was never invoked, clustered templates produced no matcher-status output. Added the same pattern: track whether the callback fires viaatomic.Bool, and if not, synthesize a failure event per operator in the cluster with properly parsed URL fields.Proof
Before (templates with
matchers-condition: andmissing from output):After (all templates reported):
Before (template output not returned or is minimized):
After (all templates/fields reported):
Before (unit tests):
After
Checklist
Summary by CodeRabbit
Bug Fixes
Tests