MCPcopy Create free account
hub / github.com/apache/tomcat / RateLimitFilter

Class RateLimitFilter

java/org/apache/catalina/filters/RateLimitFilter.java:80–334  ·  view source on GitHub ↗

Servlet filter that can help mitigate Denial of Service (DoS) and Brute Force attacks by limiting the number of a requests that are allowed from a single IP address within a time window (also referred to as a time bucket), e.g. 300 Requests per 60 seconds. The filter works by incrementi

Source from the content-addressed store, hash-verified

78 * </p>
79 */
80public class RateLimitFilter extends FilterBase {
81
82 /**
83 * Default duration in seconds.
84 */
85 public static final int DEFAULT_BUCKET_DURATION = 60;
86
87 /**
88 * Default number of requests per duration.
89 */
90 public static final int DEFAULT_BUCKET_REQUESTS = 300;
91
92 /**
93 * Default value for enforce.
94 */
95 public static final boolean DEFAULT_ENFORCE = true;
96
97 /**
98 * Default value of the expose headers flag.
99 */
100 public static final boolean DEFAULT_EXPOSE_HEADERS = false;
101
102 /**
103 * Name of the rate limit policy header field defined in
104 * <a href="https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers">RateLimit header fields for HTTP
105 * (draft)</a>.
106 */
107 public static final String HEADER_RATE_LIMIT_POLICY = "RateLimit-Policy";
108
109 /**
110 * Name of the rate limit remaining quota header field defined in
111 * <a href="https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers">RateLimit header fields for HTTP
112 * (draft)</a>.
113 */
114 public static final String HEADER_RATE_LIMIT = "RateLimit";
115
116 /**
117 * Default status code to return if requests per duration is exceeded.
118 */
119 public static final int DEFAULT_STATUS_CODE = 429;
120
121 /**
122 * Default status message to return if requests per duration is exceeded.
123 */
124 public static final String DEFAULT_STATUS_MESSAGE = "Too many requests";
125
126 /**
127 * Request attribute that will contain the number of requests per duration.
128 */
129 public static final String RATE_LIMIT_ATTRIBUTE_COUNT = "org.apache.catalina.filters.RateLimitFilter.Count";
130
131 transient RateLimiter rateLimiter;
132
133 private String rateLimitClassName = "org.apache.catalina.util.FastRateLimiter";
134
135 private int bucketRequests = DEFAULT_BUCKET_REQUESTS;
136
137 private int bucketDuration = DEFAULT_BUCKET_DURATION;

Callers

nothing calls this directly

Calls 2

getLogMethod · 0.95
getManagerMethod · 0.95

Tested by

no test coverage detected