Skip to content

Commit 944332b

Browse files
committed
Improvements to HTTP/2 overhead protection.
1 parent 30f8063 commit 944332b

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

java/org/apache/coyote/http2/Http2Protocol.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public class Http2Protocol implements UpgradeProtocol {
6363
// Maximum amount of streams which can be concurrently executed over
6464
// a single connection
6565
static final int DEFAULT_MAX_CONCURRENT_STREAM_EXECUTION = 20;
66-
66+
// Default factor used when adjusting overhead count for overhead frames
6767
static final int DEFAULT_OVERHEAD_COUNT_FACTOR = 10;
68+
// Default factor used when adjusting overhead count for reset frames
69+
static final int DEFAULT_OVERHEAD_RESET_FACTOR = 50;
6870
// Not currently configurable. This makes the practical limit for
6971
// overheadCountFactor to be ~20. The exact limit will vary with traffic
7072
// patterns.
@@ -98,6 +100,7 @@ public class Http2Protocol implements UpgradeProtocol {
98100
private int maxTrailerCount = Constants.DEFAULT_MAX_TRAILER_COUNT;
99101
private int maxTrailerSize = Constants.DEFAULT_MAX_TRAILER_SIZE;
100102
private int overheadCountFactor = DEFAULT_OVERHEAD_COUNT_FACTOR;
103+
private int overheadResetFactor = DEFAULT_OVERHEAD_RESET_FACTOR;
101104
private int overheadContinuationThreshold = DEFAULT_OVERHEAD_CONTINUATION_THRESHOLD;
102105
private int overheadDataThreshold = DEFAULT_OVERHEAD_DATA_THRESHOLD;
103106
private int overheadWindowUpdateThreshold = DEFAULT_OVERHEAD_WINDOW_UPDATE_THRESHOLD;
@@ -339,6 +342,20 @@ public void setOverheadCountFactor(int overheadCountFactor) {
339342
}
340343

341344

345+
public int getOverheadResetFactor() {
346+
return overheadResetFactor;
347+
}
348+
349+
350+
public void setOverheadResetFactor(int overheadResetFactor) {
351+
if (overheadResetFactor < 0) {
352+
this.overheadResetFactor = 0;
353+
} else {
354+
this.overheadResetFactor = overheadResetFactor;
355+
}
356+
}
357+
358+
342359
public int getOverheadContinuationThreshold() {
343360
return overheadContinuationThreshold;
344361
}

java/org/apache/coyote/http2/Http2UpgradeHandler.java

+2
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,7 @@ public void reset(int streamId, long errorCode) throws Http2Exception {
18121812
log.debug(sm.getString("upgradeHandler.reset.receive", getConnectionId(), Integer.toString(streamId),
18131813
Long.toString(errorCode)));
18141814
}
1815+
increaseOverheadCount(FrameType.RST, getProtocol().getOverheadResetFactor());
18151816
AbstractNonZeroStream abstractNonZeroStream = getAbstractNonZeroStream(streamId, true);
18161817
abstractNonZeroStream.checkState(FrameType.RST);
18171818
if (abstractNonZeroStream instanceof Stream) {
@@ -1945,6 +1946,7 @@ public void incrementWindowSize(int streamId, int increment) throws Http2Excepti
19451946

19461947
@Override
19471948
public void priorityUpdate(int prioritizedStreamID, Priority p) throws Http2Exception {
1949+
increaseOverheadCount(FrameType.PRIORITY_UPDATE);
19481950
AbstractNonZeroStream abstractNonZeroStream = getAbstractNonZeroStream(prioritizedStreamID, true);
19491951
if (abstractNonZeroStream instanceof Stream) {
19501952
Stream stream = (Stream) abstractNonZeroStream;

webapps/docs/changelog.xml

+3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@
163163
<fix>
164164
Align validation of HTTP trailer fields with standard fields. (markt)
165165
</fix>
166+
<fix>
167+
Improvements to HTTP/2 overhead protection. (markt)
168+
</fix>
166169
</changelog>
167170
</subsection>
168171
<subsection name="Jasper">

webapps/docs/config/http2.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,21 @@
222222
count starts at <code>-10 * overheadCountFactor</code>. The count is
223223
decreased by 20 for each data frame sent or received and each headers frame
224224
received. The count is increased by the <code>overheadCountFactor</code>
225-
for each setting received, priority frame received and ping received. If
225+
for each setting, priority, priority update and ping frame received. If
226226
the overhead count exceeds zero, the connection is closed. A value of less
227227
than <code>1</code> disables this protection. In normal usage a value of
228228
approximately <code>20</code> or higher will close the connection before
229229
any streams can complete. If not specified, a default value of
230230
<code>10</code> will be used.</p>
231231
</attribute>
232232

233+
<attribute name="overheadResetFactor" required="false">
234+
<p>The amount by which the overhead count (see
235+
<strong>overheadCountFactor</strong>) will be increased for each reset
236+
frame received. If not specified, a default value of <code>50</code> will
237+
be used. A value of less than zero will be treated as zero.</p>
238+
</attribute>
239+
233240
<attribute name="overheadDataThreshold" required="false">
234241
<p>The threshold below which the average payload size of the current and
235242
previous non-final <code>DATA</code> frames will trigger an increase in

0 commit comments

Comments
 (0)