I would like to prevent DDOS attacks on my spring boot 2 web application and I came across the framework bucket4j
(bucket4j-github). My application will run on heroku, and there they suggested doing so (Heroku-Link)
So far so good. I am now trying to implement bucket4j
and I would expect after that, in case I press F5
very fast and frequent, something would happen, an error will occure or something like that. But it behaves as it would without the bucket4j
framework, the request has been all answered.
My target is to limit the rate from an ip. Currently I just tried from localhost.
What I have so far:
pom.xml
<dependency>
<groupId>com.giffing.bucket4j.spring.boot.starter</groupId>
<artifactId>bucket4j-spring-boot-starter</artifactId>
<version>0.1.15</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency><!-- Somehow I needed that since bucket4j-->
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>1.2.2</version>
</dependency>
application.properties
# CACHE
spring.cache.jcache.config=classpath:ehcache.xml
# RATE LIMIT
bucket4j.enabled=true
bucket4j.filters[0].cache-name=buckets
bucket4j.filters[0].filter-method=servlet
bucket4j.filters[0].url=/*
bucket4j.filters[0].rate-limits[0].bandwidths[0].capacity=10
bucket4j.filters[0].rate-limits[0].bandwidths[0].time=1
bucket4j.filters[0].rate-limits[0].bandwidths[0].unit=minutes
bucket4j.filters[0].rate-limits[0].expression=getRemoteAddress()
bucket4j.filters[0].rate-limits[0].bandwidths[0].fixed-refill-interval=0
bucket4j.filters[0].rate-limits[0].bandwidths[0].fixed-refill-interval-unit=minutes
ehcache.xml
<config ... >
<cache alias="buckets">
<expiry><ttl unit="seconds">3600</ttl></expiry>
<heap unit="entries">1000000</heap>
</cache>
</config>
What am I missing, or did I missunderstand the framework? Thanks for hints.