Allowlist request options forwarded from the WebSocket handler#1393
Open
TristanInSec wants to merge 1 commit intocdapio:developfrom
Open
Allowlist request options forwarded from the WebSocket handler#1393TristanInSec wants to merge 1 commit intocdapio:developfrom
TristanInSec wants to merge 1 commit intocdapio:developfrom
Conversation
The 'request' action in Aggregator#onSocketData currently passes the
entire client-supplied resource object directly to the request library:
request(r, emitResponse.bind(this, r))
Before that call the server injects its own Authorization header and
proxy-user identity header into r.headers, so every field present on
the resource object becomes a client-controllable option on an
outbound request that is already carrying server credentials. The
request library recognises a number of fields that the WebSocket
client has no legitimate reason to set, notably proxy, tunnel, auth,
cert, key, ca, pfx, agent, agentOptions, baseUrl, strictSSL,
rejectUnauthorized, pool, localAddress, har, aws, oauth, hawk, and
httpSignature.
Introduce buildSafeRequestOptions(resource): it copies only a fixed
allowlist of fields (method, url/uri, headers, body/json/form/formData/
multipart, qs/qsStringifyOptions/useQuerystring, encoding, gzip,
timeout, followRedirect/followAllRedirects/maxRedirects) onto a fresh
object that is then handed to request(). The original resource object
continues to be bound into emitResponse so the response path (id,
requestOrigin, startTs, etc.) is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
'request'action insideAggregator#onSocketDatacurrently forwards the entire client-suppliedresourceobject straight into therequestHTTP library:Because the server first injects its own
Authorizationheader (and, in proxy mode, a user-identity header) intor.headers, every field that happens to sit onrbecomes a client-controllable option on an outbound request that is already carrying server credentials. Therequestlibrary recognises several options the WebSocket client has no business setting:proxy,tunnelauthcert,key,ca,pfxagent,agentOptionsbaseUrlstrictSSL,rejectUnauthorizedpool,localAddresshar,aws,oauth,hawk,httpSignatureChanges
REQUEST_OPTION_ALLOWLISTandbuildSafeRequestOptions(resource)inserver/aggregator.js. The helper copies only a fixed set of fields —method,url/uri,headers,body/json/form/formData/multipart,qs/qsStringifyOptions/useQuerystring,encoding,gzip,timeout,followRedirect/followAllRedirects/maxRedirects— onto a fresh object, so unknown/dangerous fields are dropped before they reachrequest().'request'case now callsrequest(buildSafeRequestOptions(r), ...). The originalrcontinues to be bound intoemitResponse, so fields consumed on the response side (id,requestOrigin,startTs, etc.) are unaffected.Testing
Exercised
buildSafeRequestOptionsin isolation against an input that mixes legitimate fields with the full list of disallowed options. The resulting object contained onlymethod,url,headers, andbody;proxy,auth,cert,agent,strictSSL,baseUrl,har,aws,oauth,hawk, and the metadata fields (id,requestOrigin,startTs,templateid,pluginid) were all dropped.