Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2015-04-29 20:44:44 -0400
committerJan Bartel2015-04-29 20:44:44 -0400
commite30c05cc2b3ad9dc9c17ab99f746f67af12f3e20 (patch)
tree1fda04005b28a8d7ee1f4d86fc6e540bd2f30582 /jetty-servlets
parent15eb1081e90c10267a8c9cdac1756e8ddeca98bf (diff)
parent25474ff7ab41a93d3c89de7ddc3f04b384c51762 (diff)
downloadorg.eclipse.jetty.project-e30c05cc2b3ad9dc9c17ab99f746f67af12f3e20.tar.gz
org.eclipse.jetty.project-e30c05cc2b3ad9dc9c17ab99f746f67af12f3e20.tar.xz
org.eclipse.jetty.project-e30c05cc2b3ad9dc9c17ab99f746f67af12f3e20.zip
Merge remote-tracking branch 'origin/jetty-9.2.x'
Conflicts: tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java tests/test-integration/src/test/resources/BIOHttp.xml tests/test-integration/src/test/resources/BIOHttps.xml tests/test-integration/src/test/resources/NIOHttp.xml tests/test-integration/src/test/resources/NIOHttps.xml
Diffstat (limited to 'jetty-servlets')
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java16
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java21
2 files changed, 27 insertions, 10 deletions
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
index 0b6c6ea45f..44ee4af813 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
@@ -719,6 +719,10 @@ public class DoSFilter implements Filter
prefix -= 8;
++index;
}
+
+ if (index == result.length)
+ return result;
+
// Sets the _prefix_ most significant bits to 1
result[index] = (byte)~((1 << (8 - prefix)) - 1);
return result;
@@ -1045,6 +1049,18 @@ public class DoSFilter implements Filter
_whitelist.addAll(result);
LOG.debug("Whitelisted IP addresses: {}", result);
}
+
+ /**
+ * Set a list of IP addresses that will not be rate limited.
+ *
+ * @param values whitelist
+ */
+ public void setWhitelist(List<String> values)
+ {
+ clearWhitelist();
+ _whitelist.addAll(values);
+ LOG.debug("Whitelisted IP addresses: {}", values);
+ }
/**
* Clears the list of whitelisted IP addresses
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java
index caa7a1ac16..824d623afa 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java
@@ -79,19 +79,20 @@ public class DoSFilterTest extends AbstractDoSFilterTest
{
DoSFilter filter = new DoSFilter();
List<String> whitelist = new ArrayList<String>();
- whitelist.add("192.168.0.1");
+ whitelist.add("192.168.0.1/32");
whitelist.add("10.0.0.0/8");
whitelist.add("4d8:0:a:1234:ABc:1F:b18:17");
whitelist.add("4d8:0:a:1234:ABc:1F:0:0/96");
- Assert.assertTrue(filter.checkWhitelist(whitelist, "192.168.0.1"));
- Assert.assertFalse(filter.checkWhitelist(whitelist, "192.168.0.2"));
- Assert.assertFalse(filter.checkWhitelist(whitelist, "11.12.13.14"));
- Assert.assertTrue(filter.checkWhitelist(whitelist, "10.11.12.13"));
- Assert.assertTrue(filter.checkWhitelist(whitelist, "10.0.0.0"));
- Assert.assertFalse(filter.checkWhitelist(whitelist, "0.0.0.0"));
- Assert.assertTrue(filter.checkWhitelist(whitelist, "4d8:0:a:1234:ABc:1F:b18:17"));
- Assert.assertTrue(filter.checkWhitelist(whitelist, "4d8:0:a:1234:ABc:1F:b18:0"));
- Assert.assertFalse(filter.checkWhitelist(whitelist, "4d8:0:a:1234:ABc:1D:0:0"));
+ filter.setWhitelist(whitelist);
+ Assert.assertTrue(filter.checkWhitelist("192.168.0.1"));
+ Assert.assertFalse(filter.checkWhitelist("192.168.0.2"));
+ Assert.assertFalse(filter.checkWhitelist("11.12.13.14"));
+ Assert.assertTrue(filter.checkWhitelist("10.11.12.13"));
+ Assert.assertTrue(filter.checkWhitelist("10.0.0.0"));
+ Assert.assertFalse(filter.checkWhitelist("0.0.0.0"));
+ Assert.assertTrue(filter.checkWhitelist("4d8:0:a:1234:ABc:1F:b18:17"));
+ Assert.assertTrue(filter.checkWhitelist("4d8:0:a:1234:ABc:1F:b18:0"));
+ Assert.assertFalse(filter.checkWhitelist("4d8:0:a:1234:ABc:1D:0:0"));
}
private boolean hitRateTracker(DoSFilter doSFilter, int sleep) throws InterruptedException

Back to the top