feat: CAPTCHA session ID

This commit is contained in:
Roi Feng
2025-02-19 22:24:45 -05:00
parent 51df50a72e
commit 12c7473e36
7 changed files with 82 additions and 14 deletions

View File

@ -70,8 +70,9 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusServiceUnavailable)
w.Header().Set("Set-Cookie", "__torii_session_id="+string(decision.ResponseData)+"; Path=/; Max-Age=86400; Priority=High; HttpOnly;")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusServiceUnavailable)
if err = tpl.Execute(w, nil); err != nil {
log.Printf("Error template: %v", err)
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)

View File

@ -29,13 +29,21 @@ func CheckTorii(w http.ResponseWriter, r *http.Request, reqData dataType.UserReq
}
return
} else if bytes.Compare(decision.ResponseData, []byte("good")) == 0 {
w.Header().Set("Set-Cookie", "__torii_clearance="+string(check.GenClearance(reqData, *ruleSet))+"; Path=/; HttpOnly")
w.Header().Set("Set-Cookie", "__torii_clearance="+string(check.GenClearance(reqData, *ruleSet))+"; Path=/; Max-Age=86400; Priority=High; HttpOnly;")
w.WriteHeader(http.StatusOK)
_, err := w.Write(decision.ResponseData)
if err != nil {
log.Printf("Error writing response: %v", err)
return
}
} else if bytes.Compare(decision.ResponseData, []byte("timeout")) == 0 {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("timeout"))
if err != nil {
log.Printf("Error writing response: %v", err)
return
}
return
} else {
//should not be here
w.WriteHeader(http.StatusInternalServerError)