Skip to content

Commit 98322d0

Browse files
committed
Updates dependencies and enhances IP resolution
Updates Spring Boot and Logstash Logback Encoder dependencies to their latest compatible versions. Improves IP address resolution by prioritizing the CF-Connecting-IP and X-Forwarded-For headers, ensuring accurate client IP detection even when behind a proxy or CDN. Falls back to request.getRemoteAddr() if headers are not present or empty.
1 parent 0fc31ce commit 98322d0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.3.4</version>
8+
<version>3.4.1</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>com.dmware</groupId>
@@ -87,7 +87,7 @@
8787
<dependency>
8888
<groupId>net.logstash.logback</groupId>
8989
<artifactId>logstash-logback-encoder</artifactId>
90-
<version>9.0</version>
90+
<version>7.4</version>
9191
</dependency>
9292
<dependency>
9393
<groupId>com.bucket4j</groupId>

src/main/java/com/dmware/api_onibusbh/infra/RateLimitingFilter.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ public class RateLimitingFilter extends OncePerRequestFilter {
4040
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
4141
throws ServletException, IOException {
4242

43-
String clientIp = request.getRemoteAddr();
43+
String clientIp = request.getHeader("CF-Connecting-IP");
44+
if (clientIp == null || clientIp.isEmpty()) {
45+
clientIp = request.getHeader("X-Forwarded-For");
46+
if (clientIp != null && !clientIp.isEmpty()) {
47+
clientIp = clientIp.split(",")[0].trim();
48+
}
49+
}
50+
if (clientIp == null || clientIp.isEmpty()) {
51+
clientIp = request.getRemoteAddr();
52+
}
4453
Bucket bucket = buckets.computeIfAbsent(clientIp, this::createNewBucket);
4554

4655
ConsumptionProbe probe = bucket.tryConsumeAndReturnRemaining(1);

0 commit comments

Comments
 (0)