Skip to content

Fix rate-limiting bypass via Authorization header - #1959

Open
Yavor16 wants to merge 1 commit into
masterfrom
fix-rate-limiting-auth-bypass-LMCROSSITXSADEPLOY-1733
Open

Yavor16 wants to merge 1 commit into
masterfrom
fix-rate-limiting-auth-bypass-LMCROSSITXSADEPLOY-1733

Conversation

@Yavor16

@Yavor16 Yavor16 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
64.2% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Comment on lines +84 to +91
try {
TokenGenerator tokenGenerator = tokenGeneratorFactory.createGenerator(scheme);
return tokenGenerator.generate(token);
} catch (AuthenticationException | ResponseStatusException e) {
failedAuthRateLimiter.recordFailedAttempt(ip, username);
throw e;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so here we return a auth token and in case of an error - go into the catch. The catch then internally calls failedAuthRateLimiter.recordFailedAttempt and following the methods in it, it uses the consumeToken method which can throw a OperationLimitExceeded exception and if that happens, we would directly exit the catch and the final line "throw e" - will not be reached at all. THis way we lose the original exception and just get a simple rate limit one. Maybe try to come up with a way to preserve the whole original exception or at least its message or code etc.

Comment on lines +29 to +30
private static final Duration REFILL_PERIOD = Duration.ofHours(1);
private static final long TOKENS_PER_ATTEMPT = 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe extract these constants so both AnonymousrateLimiter and the FailedAuthRateLimiter can share them.

* {@link OperationRateLimitExceededException} is raised. Throttling is a no-op unless explicitly enabled.
*/
@Named
public class FailedAuthRateLimiter {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the OperationRateLimiter and AnonymousRateLimiter and FailedAuthRateLimiter all use the same table to store their entries the operation_rate_limit_bucket table - how is the table cleaned since the CleanUpJob goes through the list of cleaners and the OperationRateLimitBucketCleaner does not implement the Cleaner interface.

I see that it is now set to go every hour, but at the begining we have a guard for the OPERATION_RATE_LIMITING_ENABLED boolean and it is by default set to false and if it is false for the deploy-service, then this cleaner does not execute at all.
Maybe add checks for this particular cleaner to be started if we have FAILED_AUTH_RATE_LIMITING_ENABLED enabled and also it is not part of your code change but I think It would be better to make the cleaner go with all the other cleaners executed by the clean up job - by making it implement the Cleaner interface as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants