Skip to content

Commit

Permalink
Fix broken http header filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Mar 21, 2023
1 parent 285ce54 commit 72cc9a8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/js/httpheader-filtering.js
Expand Up @@ -41,12 +41,10 @@ const $exceptions = new Set();
let acceptedCount = 0;
let discardedCount = 0;

const headerIndexFromName = function(name, headers) {
let i = headers.length;
while ( i-- ) {
if ( headers[i].name.toLowerCase() === name ) {
return i;
}
const headerIndexFromName = function(name, headers, start = 0) {
for ( let i = start; i < headers.length; i++ ) {
if ( headers[i].name.toLowerCase() !== name ) { continue; }
return i;
}
return -1;
};
Expand Down Expand Up @@ -138,7 +136,7 @@ httpheaderFilteringEngine.fromCompiledContent = function(reader) {
duplicates.add(fingerprint);
const args = reader.args();
if ( args.length < 4 ) { continue; }
filterDB.store(args[1], args[2], args[3].slice(15, -1));
filterDB.store(args[1], args[2], args[3]);
}
};

Expand Down Expand Up @@ -175,18 +173,20 @@ httpheaderFilteringEngine.apply = function(fctxt, headers) {
const hasGlobalException = $exceptions.has('');

let modified = false;
let i = 0;

for ( const name of $headers ) {
const isExcepted = hasGlobalException || $exceptions.has(name);
if ( isExcepted ) {
if ( logger.enabled ) {
logOne(true, hasGlobalException ? '' : name, fctxt);
}
continue;
}
i = 0;
for (;;) {
const i = headerIndexFromName(name, headers);
i = headerIndexFromName(name, headers, i);
if ( i === -1 ) { break; }
const isExcepted = hasGlobalException || $exceptions.has(name);
if ( isExcepted ) {
if ( logger.enabled ) {
logOne(true, hasGlobalException ? '' : name, fctxt);
}
break;
}
headers.splice(i, 1);
if ( logger.enabled ) {
logOne(false, name, fctxt);
Expand Down

0 comments on commit 72cc9a8

Please sign in to comment.