feat(assessment): record capture hints and keep one window per attempt

This commit is contained in:
shira committed 2026-10-11 13:16:52 +03:00
1 parent c975a0d506
commit bb917bf62e
108 files changed
+6649 -139

No files matched your search

@@ -18,12 +18,13 @@ import (
)
// SignalDigester derives the keyed digests that stand for an answer, a login
// session, and a client network in the stored server signals. No digest can be
// turned back into what it stands for without the server secret.
// session, a client network, and a User-Agent in the stored server signals. No
// digest can be turned back into what it stands for without the server secret.
type SignalDigester interface {
AssessmentAnswerFingerprint(familyID uuid.UUID, familyVersion int32, canonicalAnswer []byte) domain.AssessmentDigest
AssessmentSessionDigest(attemptID, sessionID uuid.UUID) domain.AssessmentDigest
AssessmentNetworkDigest(attemptID uuid.UUID, clientKey string) domain.AssessmentDigest
AssessmentAgentDigest(attemptID uuid.UUID, userAgent string) domain.AssessmentDigest
// AssessmentDigestKeyVersion is the key generation of the digests above.
AssessmentDigestKeyVersion() int16
}
@@ -41,13 +42,15 @@ const (
signalReviewEndedKey = "ended"
)
// RequestOrigin is what the HTTP adapter knows about the sender of an answer or
// a signal batch: the authenticated session and the limiter key of the client
// address. It is used only to make digests and is never stored or logged. An
// empty ClientKey means the address could not be resolved.
// RequestOrigin is what the HTTP adapter knows about the sender of an answer, a
// signal batch, or a work session hold: the authenticated session, the limiter
// key of the client address, and the User-Agent. It is used only to make
// digests and is never stored or logged. An empty ClientKey means the address
// could not be resolved, and an empty UserAgent that the request had none.
type RequestOrigin struct {
SessionID uuid.UUID
ClientKey string
UserAgent string
}
// SignalObserver records server-side facts of real attempts and schedules the
@@ -150,9 +153,9 @@ func answeredSince(snapshot domain.AssessmentAttemptSnapshot) bool {
return false
}
// recordOrigin stores the session and network digests of an accepted request
// when they differ from the last stored mark, which is enough to count session
// alternations and distinct networks. A request without a session is not
// recordOrigin stores the session, network, and User-Agent digests of an
// accepted request when they differ from the last stored mark, which is enough
// to count session alternations, distinct networks, and distinct agents. A request without a session is not
// marked. The caller holds the attempt row lock, so the last mark is stable.
func (observer *SignalObserver) recordOrigin(
ctx context.Context,
@@ -178,11 +181,15 @@ func (observer *SignalObserver) recordOrigin(
if origin.ClientKey != "" {
mark.NetworkDigest = observer.digester.AssessmentNetworkDigest(attemptID.UUID(), origin.ClientKey)
}
if origin.UserAgent != "" {
mark.AgentDigest = observer.digester.AssessmentAgentDigest(attemptID.UUID(), origin.UserAgent)
}
last, found, err := repository.LastOriginMark(ctx, attemptID)
if err != nil {
return fmt.Errorf("%s - read last mark: %w", location, err)
}
if found && last.SessionDigest == mark.SessionDigest && last.NetworkDigest == mark.NetworkDigest && last.KeyVersion == mark.KeyVersion {
if found && last.SessionDigest == mark.SessionDigest && last.NetworkDigest == mark.NetworkDigest &&
last.AgentDigest == mark.AgentDigest && last.KeyVersion == mark.KeyVersion {
return nil
}
if err := repository.SaveOriginMark(ctx, mark); err != nil {
@@ -409,8 +416,10 @@ func evaluateReview(
measures := domain.AssessmentReviewMeasures{
AnsweredItems: times.Answered, FastAnswers: times.Fast, DeviatingAnswers: times.Deviating,
ParallelAlternations: anomalies.ParallelAlternations, ExtraNetworks: anomalies.ExtraNetworks,
ExtraAgents: anomalies.ExtraAgents,
ClientFocusLossMS: inputs.ClientFocusLossMS, ClientClipboardEvents: inputs.ClientClipboardCount,
ClientFullscreenExits: inputs.ClientFullscreenExit,
ClientFullscreenExits: inputs.ClientFullscreenExit, ClientScreenshotKeys: inputs.ClientScreenshotKeys,
ClientDevtoolsOpens: inputs.ClientDevtoolsOpens,
}
if len(best) > 0 {
measures.DuplicateEvidenceBits = best[0].EvidenceBits