sync: dev to extern-contrib - #1020
Merged
Merged
Conversation
评测队列繁忙时 XMOJ 会启用 vcode.php 图片验证码,但提交界面是脚本自己 渲染的,服务端的验证码字段在替换 DOM 时被丢弃,提交因此静默失败。 - 替换页面前先检测服务端是否渲染了验证码字段,若有则在提交按钮上方 显示验证码图片与输入框,点击图片可更换 - 提交时附带 vcode 参数;队列不繁忙时 submit.php 会忽略该字段,因此 无条件携带是安全的 - submitpage.php 在队列 >10 时显示验证码,submit.php 在 >50 时才校验, 两者可能不一致:识别到"验证码错误"时展开验证码区域并允许重新提交 - 验证码为空时在客户端拦截。提交空验证码会让服务端标记 vfail,此后 验证码会从 4 位数字变成 8 位字母数字,直到会话结束 - 新增 AutoCaptcha 开关,通过 captchaSolve 自动识别 4 位数字验证码; 识别结果非 4 位数字时不填入,8 位字母验证码不送识别,均可手动填写 Closes #420 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
实测 Workers AI 的视觉模型都读不准 XMOJ 的验证码:以 7602 为例, llava-1.5-7b 返回 600,llama-4-scout 返回 1834,mistral-small-3.1 返回 1234;另一张 7908 的图 llava 返回 9990。 四位数字的错误答案会通过校验被提交,失败后服务端置 vfail,验证码从 4 位数字升级为 8 位字母数字,直到会话结束,比留空更糟。因此把 AutoCaptcha 改为默认关闭,仅作为实验性功能保留接口。 顺带把默认关闭项提取为 DefaultOffSettings,供 UtilityEnabled 与设置 列表共用——两处都会给缺失的项写入默认值,不一致时先执行的一方说了算。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
vcode.php 用 imagettftext(15px, Vera.ttf) 在固定位置绘制 4 位数字, 每个字形在不同验证码之间逐像素相同,因此模板匹配可以直接读出来, 不需要把图片发给任何模型。 背景是一种随机色,文字是它的反色,噪点是第三种随机色:取出现次数 最多的颜色作为背景即可定位文字颜色。跳过 1 像素黑边,否则接近白色 的背景会让黑边被当成文字。切分出的字形与 10 个模板逐一比对,除了 奖励命中的笔画,也惩罚模板之外的墨点——否则带噪点的 0 会和 9 打平。 只有切出恰好 4 个字形、且每个字形的最佳得分领先第二名 4 分以上时 才填入,否则留空由用户填写:错误答案会触发 vfail,把验证码升级成 8 位字母数字,比留空更糟。 实测 300 张生成样本 227 正确 0 错误,40 张真实验证码填入 31 张, 14 张人工标注样本 13 正确 1 放弃 0 错误。因为不会填错,AutoCaptcha 恢复默认开启,同时移除 captchaSolve 依赖与相关 @connect。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
验证码为空的拦截原来只在"提交"的处理函数里。检查未通过时页面会留下 "强制提交"按钮,而真正发出请求的是它:这段时间里用户可以点击验证码 图片换一张(会清空输入框)或手动清空,再点"强制提交"就会带着空验证码 发出请求,触发本要避免的 vfail 升级。 把拦截提取为 CaptchaIsMissing,在实际发出请求的 PassCheck 处理函数 开头也调用一次,并在拦截时重新隐藏"强制提交"按钮。 Reported-by: chatgpt-codex-connector Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Reviewer's GuideImplements local image-based solving for XMOJ’s vcode captcha on the submit page, wires it into the submission flow with safety checks, refactors default-off settings into a shared constant, and bumps the script/package versions to 3.6.4. Sequence diagram for captcha-aware code submissionsequenceDiagram
participant User
participant SubmitPage
participant Captcha as vcode.php
participant Submit as submit.php
SubmitPage->>SubmitPage: NativeCaptchaShown
alt captcha is shown
SubmitPage->>Captcha: fetch("vcode.php?" + Math.random())
Captcha-->>SubmitPage: ImageBlob
SubmitPage->>SubmitPage: GetCaptchaLength(ImageBlob)
alt four-digit captcha and AutoCaptcha enabled
SubmitPage->>SubmitPage: SolveCaptcha(ImageBlob)
SubmitPage->>SubmitPage: Fill #vcode when confidence is sufficient
else unsupported or uncertain captcha
SubmitPage-->>User: Request manual input
end
end
User->>SubmitPage: PassCheck.click
SubmitPage->>SubmitPage: CaptchaIsMissing()
alt captcha missing
SubmitPage-->>User: Show captcha-required error
else captcha available
SubmitPage->>Submit: POST submission with GetCaptchaParameter()
alt captcha rejected
Submit-->>SubmitPage: Response containing 验证码错误
SubmitPage->>SubmitPage: RefreshCaptcha("")
SubmitPage-->>User: Show retry message
else accepted
Submit-->>SubmitPage: Submission response or redirect
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Deploying xmoj-script-dev-channel with
|
| Latest commit: |
8e9b445
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://55fc6201.xmoj-script-dev-channel.pages.dev |
Contributor
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. The change alters captcha enforcement and automatically submits locally recognized answers, so a parsing or session-state mistake could consume captcha attempts, escalate the challenge, or cause submissions to be rejected or mishandled. Reverting stops the behavior but cannot undo failed captcha attempts or submissions already made.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
sync-branches: New code has just landed in dev, so let's bring extern-contrib up to speed!
Summary by Sourcery
Improve submission reliability during busy judge queues by adding robust captcha handling and local recognition.
New Features:
Bug Fixes:
Enhancements:
Build:
Summary by cubic
Show and submit the server captcha on the custom submit page to prevent silent failures when the judge queue is busy. Previously the page dropped the vcode field; now it renders the captcha, includes vcode in POSTs, and blocks blank submissions.
package.jsonand updates release notes in Update.json.Written for commit 8e9b445. Summary will update on new commits.