fix(remote_judger/codeforces): include referer when submitting problem

This commit is contained in:
Baoshuo Ren 2023-02-06 10:24:33 +08:00
parent 3d63a011ac
commit a5a2b4547b
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -146,8 +146,8 @@ export default class CodeforcesProvider implements IBasicProvider {
return _tta;
}
async getCsrfToken(url: string) {
const { text: html } = await this.get(url);
async getCsrfToken(url: string, referer = '') {
const { text: html } = await this.get(url).set('Referer', referer);
const {
window: { document },
} = new JSDOM(html);
@ -257,9 +257,17 @@ export default class CodeforcesProvider implements IBasicProvider {
}
const [type, contestId, problemId] = parseProblemId(id);
const referer =
this.account.endpoint +
(type !== 'GYM'
? `/problemset/problem/${contestId}/${problemId}`
: `/gym/${contestId}/problem/${problemId}`);
logger.debug('referer', referer);
const [csrf, ftaa, bfaa] = await this.getCsrfToken(
type !== 'GYM' ? '/problemset/submit' : `/gym/${contestId}/submit`
type !== 'GYM' ? '/problemset/submit' : `/gym/${contestId}/submit`,
referer
);
logger.debug(
@ -275,7 +283,8 @@ export default class CodeforcesProvider implements IBasicProvider {
`/${
type !== 'GYM' ? 'problemset' : `gym/${contestId}`
}/submit?csrf_token=${csrf}`
).send({
)
.send({
csrf_token: csrf,
action: 'submitSolutionFormSubmitted',
programTypeId: programType.id,
@ -293,7 +302,8 @@ export default class CodeforcesProvider implements IBasicProvider {
: {
submittedProblemIndex: problemId,
}),
});
})
.set('Referer', referer);
if (error) {
end({