fix cookie capture event sometimes output before all captures were completed

Signed-off-by: Ronni Skansing <rskansing@gmail.com>
This commit is contained in:
Ronni Skansing
2025-11-14 01:51:31 +01:00
parent 573703acf0
commit 723ff5592b

View File

@@ -1716,20 +1716,26 @@ func (m *ProxyHandler) checkCaptureCompletion(session *service.ProxySession, cap
if _, hasData := session.CapturedData.Load(captureName); hasData {
session.RequiredCaptures.Store(captureName, true)
// check if all required captures are complete
allComplete := true
session.RequiredCaptures.Range(func(key, value interface{}) bool {
if !value.(bool) {
allComplete = false
return false
}
return true
})
// update session complete status
allComplete := m.areAllRequiredCapturesComplete(session)
session.IsComplete.Store(allComplete)
}
}
}
// areAllRequiredCapturesComplete checks if all required captures have been completed
func (m *ProxyHandler) areAllRequiredCapturesComplete(session *service.ProxySession) bool {
allComplete := true
session.RequiredCaptures.Range(func(key, value interface{}) bool {
if !value.(bool) {
allComplete = false
return false
}
return true
})
return allComplete
}
func (m *ProxyHandler) checkAndSubmitCookieBundleWhenComplete(session *service.ProxySession, req *http.Request) {
if session.CampaignRecipientID == nil || session.CampaignID == nil {
return
@@ -1739,9 +1745,8 @@ func (m *ProxyHandler) checkAndSubmitCookieBundleWhenComplete(session *service.P
return
}
// only submit cookie bundle when ALL captures (including non-cookie ones) are complete
// this ensures we capture the final state after all authentication attempts
if !session.IsComplete.Load() {
// only submit cookie bundle when ALL required captures are complete
if !m.areAllRequiredCapturesComplete(session) {
return
}