Skip to content

Commit e97a20e

Browse files
JSap0914lpinca
authored andcommitted
[fix] Reject offers with client_max_window_bits below config
When a server is configured with `clientMaxWindowBits = N` and a client offers `client_max_window_bits = M` where `M < N`, the server must not respond with a value greater than `M`. Previously the server accepted such offers and responded with `client_max_window_bits = N`. The analogous check for `serverMaxWindowBits` already existed; this commit adds the symmetric check for `clientMaxWindowBits`.
1 parent 787ebf2 commit e97a20e

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/permessage-deflate.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ class PerMessageDeflate {
167167
(typeof opts.serverMaxWindowBits === 'number' &&
168168
opts.serverMaxWindowBits > params.server_max_window_bits))) ||
169169
(typeof opts.clientMaxWindowBits === 'number' &&
170-
!params.client_max_window_bits)
170+
(typeof params.client_max_window_bits === 'number'
171+
? opts.clientMaxWindowBits > params.client_max_window_bits
172+
: !params.client_max_window_bits))
171173
) {
172174
return false;
173175
}

test/permessage-deflate.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,21 @@ describe('PerMessageDeflate', () => {
213213
);
214214
});
215215

216+
it('throws an error if client_max_window_bits is less than configuration', () => {
217+
const perMessageDeflate = new PerMessageDeflate({
218+
isServer: true,
219+
clientMaxWindowBits: 11
220+
});
221+
const extensions = extension.parse(
222+
'permessage-deflate; client_max_window_bits=10'
223+
);
224+
225+
assert.throws(
226+
() => perMessageDeflate.accept(extensions['permessage-deflate']),
227+
/^Error: None of the extension offers can be accepted$/
228+
);
229+
});
230+
216231
it('throws an error if client_max_window_bits is unsupported on client', () => {
217232
const perMessageDeflate = new PerMessageDeflate({
218233
isServer: true,

0 commit comments

Comments
 (0)