Skip to content

Commit b9c6c38

Browse files
committed
fix(submit): check flag length after decryption
1 parent a1d0800 commit b9c6c38

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

src/GZCTF.Test/SignatureTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,14 @@ public void TestEncryptData()
183183
output.WriteLine("公钥:");
184184
output.WriteLine(Base64.ToBase64String(publicKey.GetEncoded()));
185185

186-
const string data = "Hello, GZCTF!";
186+
var data = new string('0', 127);
187+
output.WriteLine($"原始数据:({data.Length})\n{data}");
187188
var encryptedData = CryptoUtils.EncryptData(Encoding.UTF8.GetBytes(data), publicKey);
188-
output.WriteLine($"加密数据:\n{Base64.ToBase64String(encryptedData)}");
189+
var base64EncryptedData = Base64.ToBase64String(encryptedData);
190+
output.WriteLine($"加密数据:({base64EncryptedData.Length})\n{base64EncryptedData}");
189191
var decryptedData = CryptoUtils.DecryptData(encryptedData, privateKey);
190-
output.WriteLine($"解密数据:\n{Encoding.UTF8.GetString(decryptedData)}");
192+
var decryptedString = Encoding.UTF8.GetString(decryptedData);
193+
output.WriteLine($"解密数据:({decryptedString.Length})\n{decryptedString}");
191194
Assert.Equal(data, Encoding.UTF8.GetString(decryptedData));
192195
}
193196
}

src/GZCTF/ClientApp/src/Api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,7 @@ export interface ClientFlagContext {
17221722
export interface FlagSubmitModel {
17231723
/**
17241724
* Flag content
1725-
* Fix: Prevent accidental submissions from the frontend (number/float/null) that may be incorrectly converted
17261725
* @minLength 1
1727-
* @maxLength 127
17281726
*/
17291727
flag: string;
17301728
}

src/GZCTF/ClientApp/src/components/GameChallengeModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
154154
})
155155
} catch (e) {
156156
showErrorNotification(e, t)
157+
setDisabled(false)
157158
}
158159
}
159160

src/GZCTF/Controllers/GameController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using FluentStorage;
88
using FluentStorage.Blobs;
99
using GZCTF.Middlewares;
10+
using GZCTF.Models;
1011
using GZCTF.Models.Internal;
1112
using GZCTF.Models.Request.Admin;
1213
using GZCTF.Models.Request.Game;
@@ -844,6 +845,10 @@ public async Task<IActionResult> GetChallenge([FromRoute] int id, [FromRoute] in
844845
public async Task<IActionResult> Submit([FromRoute] int id, [FromRoute] int challengeId,
845846
[FromBody] FlagSubmitModel model, CancellationToken token)
846847
{
848+
var answer = configService.DecryptApiData(model.Flag).Trim();
849+
if (answer.Length > Limits.MaxFlagLength)
850+
return BadRequest(new RequestResponse(localizer[nameof(Resources.Program.Model_FlagTooLong)]));
851+
847852
var context = await GetContextInfo(id, challengeId, token: token);
848853

849854
if (context.Result is not null)
@@ -858,7 +863,7 @@ public async Task<IActionResult> Submit([FromRoute] int id, [FromRoute] int chal
858863
Participation = context.Participation!,
859864
Status = AnswerResult.FlagSubmitted,
860865
SubmitTimeUtc = DateTimeOffset.UtcNow,
861-
Answer = configService.DecryptApiData(model.Flag).Trim()
866+
Answer = answer
862867
};
863868

864869
submission = await submissionRepository.AddSubmission(submission, token);

src/GZCTF/Models/Request/Game/FlagSubmitModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ public class FlagSubmitModel
99
{
1010
/// <summary>
1111
/// Flag content
12-
/// Fix: Prevent accidental submissions from the frontend (number/float/null) that may be incorrectly converted
1312
/// </summary>
1413
[Required(ErrorMessageResourceName = nameof(Resources.Program.Model_FlagRequired),
1514
ErrorMessageResourceType = typeof(Resources.Program))]
16-
[MaxLength(Limits.MaxFlagLength, ErrorMessageResourceName = nameof(Resources.Program.Model_FlagTooLong),
17-
ErrorMessageResourceType = typeof(Resources.Program))]
1815
public string Flag { get; set; } = string.Empty;
1916
}

0 commit comments

Comments
 (0)