Skip to content

Commit 708eef1

Browse files
devondragonclaude
andcommitted
Extract magic number to constant for token validation
Replaced hardcoded value 20 with MIN_TOKEN_LENGTH constant to improve code maintainability and make the validation logic more self-documenting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9f3ed41 commit 708eef1

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/main/java/com/digitalsanctuary/cf/turnstile/service/TurnstileValidationService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
@Service
4141
public class TurnstileValidationService {
4242
private static final String UNKNOWN = "unknown";
43+
private static final int MIN_TOKEN_LENGTH = 20;
4344

4445
private final RestClient turnstileRestClient;
4546
private final TurnstileConfigProperties properties;
@@ -231,7 +232,7 @@ public ValidationResult validateTurnstileResponseDetailed(String token, String r
231232

232233
// Basic format validation - Cloudflare tokens typically start with '0.' or '1.' followed by alphanumeric chars
233234
// and should be reasonably sized (typically 100+ chars)
234-
if (token.length() < 20) {
235+
if (token.length() < MIN_TOKEN_LENGTH) {
235236
log.warn("Turnstile validation failed: token appears to be too short to be valid (length: {})", token.length());
236237
recordError(ValidationResultType.INPUT_ERROR);
237238
return ValidationResult.inputError("Token is too short to be valid (length: " + token.length() + ")");

0 commit comments

Comments
 (0)