Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/v0.2.21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# v0.2.21

Rate-limit sign-in attempts.

## Fixed

- Password login and first-run setup share the admin auth limiter, so repeated
failed attempts from one address get 429s instead of unlimited password guessing.
2 changes: 1 addition & 1 deletion path-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.20</version>
<version>0.2.21</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class AdminAuthController {
private final GatewayProperties props;
private final ObjectMapper mapper;
private final AuditService audit;
private final com.anindra.path.config.AdminAuthLimiter authLimiter;

public record Credentials(String username, String password) {
}
Expand All @@ -45,15 +46,37 @@ public Map<String, Object> status() {

@PostMapping("/auth/setup")
public Map<String, Object> setup(@RequestBody Credentials input, HttpServletRequest request) {
AdminAuthService.SessionResult result = auth.setup(input.username(), input.password());
return sessionResponse(result, request);
limitAuthAttempts(request);
try {
AdminAuthService.SessionResult result = auth.setup(input.username(), input.password());
authLimiter.onSuccess(request.getRemoteAddr());
return sessionResponse(result, request);
} catch (RuntimeException e) {
authLimiter.onFailure(request.getRemoteAddr());
throw e;
}
}

@PostMapping("/auth/login")
public Map<String, Object> login(@RequestBody Credentials input, HttpServletRequest request) {
AdminAuthService.SessionResult result = auth.login(input.username(), input.password(),
request.getRemoteAddr(), request.getHeader("User-Agent"));
return sessionResponse(result, request);
limitAuthAttempts(request);
try {
AdminAuthService.SessionResult result = auth.login(input.username(), input.password(),
request.getRemoteAddr(), request.getHeader("User-Agent"));
authLimiter.onSuccess(request.getRemoteAddr());
return sessionResponse(result, request);
} catch (RuntimeException e) {
authLimiter.onFailure(request.getRemoteAddr());
throw e;
}
}

private void limitAuthAttempts(HttpServletRequest request) {
long retry = authLimiter.retryAfterSeconds(request.getRemoteAddr());
if (retry > 0) {
throw ApiException.rateLimited(
"Too many failed sign-in attempts. Retry in " + retry + "s.", (int) retry);
}
}

@GetMapping("/auth/me")
Expand Down
2 changes: 1 addition & 1 deletion path-spring-ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.20</version>
<version>0.2.21</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.20</version>
<version>0.2.21</version>
<packaging>pom</packaging>
<name>path-parent</name>
<description>Build parent for Path, the provider-agnostic LLM gateway, and its Spring AI adapter</description>
Expand Down