Skip to content

Commit

Permalink
fix: sanitize invalid custom protocol headers (#18854)
Browse files Browse the repository at this point in the history
  • Loading branch information
Micha Hanselmann authored and codebytere committed Jun 21, 2019
1 parent 236d552 commit 81497c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions shell/browser/net/url_request_async_asar_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ void BeforeStartInUI(base::WeakPtr<URLRequestAsyncAsarJob> job,
error = net::ERR_NOT_IMPLEMENTED;
}

// sanitize custom headers
if (request_options && request_options->is_dict()) {
const base::Value* headersDict = request_options->FindDictKey("headers");
if (headersDict) {
for (const auto& iter : headersDict->DictItems()) {
if (!iter.second.is_string()) {
args->ThrowError("Value of '" + iter.first +
"' header has to be a string");
return;
}
}
}
}

base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&URLRequestAsyncAsarJob::StartAsync, job,
Expand Down
13 changes: 13 additions & 0 deletions spec/api-protocol-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ describe('protocol module', () => {
expect(r.headers).to.include('x-great-header: sogreat')
})

it('throws an error when custom headers are invalid', (done) => {
const handler = (request, callback) => {
expect(() => callback({
path: filePath,
headers: { 'X-Great-Header': 42 }
})).to.throw(Error, 'Value of \'X-Great-Header\' header has to be a string')
done()
}
registerFileProtocol(protocolName, handler).then(() => {
ajax(protocolName + '://fake-host')
})
})

it('sends object as response', async () => {
const handler = (request, callback) => callback({ path: filePath })
await registerFileProtocol(protocolName, handler)
Expand Down

0 comments on commit 81497c7

Please sign in to comment.