security: harden slider_captcha against brute-force, replay, and bot attacks#2
Draft
BrianTran24 with Copilot wants to merge 2 commits into
Draft
security: harden slider_captcha against brute-force, replay, and bot attacks#2BrianTran24 with Copilot wants to merge 2 commits into
BrianTran24 with Copilot wants to merge 2 commits into
Conversation
…ptcha - D: Use Random.secure() for cryptographically secure puzzle position generation - C: Add maxAttempts parameter to SliderCaptcha; auto-reset captcha after N consecutive failures (default 5) - E: Track drag trail (SliderDragPoint list + timestamps) during drag gesture; expose via optional onBehaviorData callback on both SliderCaptcha and SliderCaptchaClient; add SliderMovementData.isLikelyHuman() heuristic - B: Add captchaId field to SliderCaptchaClientProvider so callers can bind each session to a server-side token and pass it in verification requests - G: SliderCaptchaService now enforces HTTPS base URLs via _assertHttps(); old broken Uri.https() call fixed - New tests for SliderMovementData heuristics and SliderCaptcha widget params" Agent-Logs-Url: https://github.com/BrianTran24/slider_captcha/sessions/966034aa-e704-4a20-898e-efe63973d8e8 Co-authored-by: BrianTran24 <179514740+BrianTran24@users.noreply.github.com>
- Use variance > 1e-10 epsilon to avoid floating-point false negatives in bot heuristic - Convert _SliderCaptchaComponent onBehaviorData to named optional parameter (consistent API) - Remove default baseUrl from SliderCaptchaService constructor to force explicit configuration" Agent-Logs-Url: https://github.com/BrianTran24/slider_captcha/sessions/966034aa-e704-4a20-898e-efe63973d8e8 Co-authored-by: BrianTran24 <179514740+BrianTran24@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The original implementation verified captcha answers entirely client-side with a predictable
Random()PRNG, no attempt limits, no session binding, no movement analysis, and plain HTTP in the example service.Changes
D — Cryptographically secure position generation
_RenderTestSliderCaptChar.create()now usesRandom.secure()instead ofRandom(), making puzzle piece positions unpredictable.C — Brute-force protection via
maxAttemptsSliderCaptchagains amaxAttemptsparameter (default5). On consecutive failures the widget auto-resets with a fresh random position and firesonConfirm(false)once.E — Drag-trail collection and bot heuristics
New
SliderDragPoint/SliderMovementDataclasses (exported from the package) capture timestamped x-positions during every drag-update. BothSliderCaptchaandSliderCaptchaClientexpose anonBehaviorDatacallback; callers forward the trail to their server for bot-detection.isLikelyHuman()applies three client-side checks: minimum point count (≥5), minimum duration (≥300 ms), and non-zero velocity variance (threshold> 1e-10to avoid float precision false negatives).B — Session token (replay-attack prevention)
SliderCaptchaClientProvideraccepts an optionalcaptchaIdfield, populated from the server'srequestID. Include it in the verification request body so the server can invalidate the token after a single use.G — HTTPS enforcement in the example service
SliderCaptchaServicenow requires an explicitbaseUrl(no default, to force conscious configuration) and assertshttps://at construction time:The pre-existing broken
Uri.https(fullUrl)call inpostAnsweris also fixed.