mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: sanitize invalid custom protocol headers (#18927)
* fix: sanitize invalid custom protocol headers (#18854) * lint fix
This commit is contained in:
committed by
Shelley Vohr
parent
3e033b4f27
commit
a603a4dde8
@@ -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,
|
||||
|
||||
@@ -342,6 +342,25 @@ describe('protocol module', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('throws an error when custom headers are invalid', (done) => {
|
||||
const handler = (request, callback) => {
|
||||
assert.throws(() => callback({
|
||||
path: filePath,
|
||||
headers: { 'X-Great-Header': 42 }
|
||||
}), /Value of 'X-Great-Header' header has to be a string/)
|
||||
done()
|
||||
}
|
||||
protocol.registerFileProtocol(protocolName, handler, (error) => {
|
||||
if (error) return done(error)
|
||||
$.ajax({
|
||||
url: protocolName + '://fake-host',
|
||||
cache: false,
|
||||
success: () => done('request succeeded but it should not'),
|
||||
error: (xhr, errorType, error) => done(error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('sends object as response', (done) => {
|
||||
const handler = (request, callback) => callback({ path: filePath })
|
||||
protocol.registerFileProtocol(protocolName, handler, (error) => {
|
||||
|
||||
Reference in New Issue
Block a user