From a5a2b4547bc80769aedbf067246864265d6a6e57 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Feb 2023 10:24:33 +0800 Subject: [PATCH] fix(remote_judger/codeforces): include referer when submitting problem --- remote_judger/src/providers/codeforces.ts | 54 ++++++++++++++--------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/remote_judger/src/providers/codeforces.ts b/remote_judger/src/providers/codeforces.ts index 2795379..e76fec6 100644 --- a/remote_judger/src/providers/codeforces.ts +++ b/remote_judger/src/providers/codeforces.ts @@ -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,25 +283,27 @@ export default class CodeforcesProvider implements IBasicProvider { `/${ type !== 'GYM' ? 'problemset' : `gym/${contestId}` }/submit?csrf_token=${csrf}` - ).send({ - csrf_token: csrf, - action: 'submitSolutionFormSubmitted', - programTypeId: programType.id, - source: code, - tabsize: 4, - sourceFile: '', - ftaa, - bfaa, - _tta: this.tta(this.getCookie('39ce7')), - ...(type !== 'GYM' - ? { - submittedProblemCode: contestId + problemId, - sourceCodeConfirmed: true, - } - : { - submittedProblemIndex: problemId, - }), - }); + ) + .send({ + csrf_token: csrf, + action: 'submitSolutionFormSubmitted', + programTypeId: programType.id, + source: code, + tabsize: 4, + sourceFile: '', + ftaa, + bfaa, + _tta: this.tta(this.getCookie('39ce7')), + ...(type !== 'GYM' + ? { + submittedProblemCode: contestId + problemId, + sourceCodeConfirmed: true, + } + : { + submittedProblemIndex: problemId, + }), + }) + .set('Referer', referer); if (error) { end({