-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: stop leaking optional query params and headers across subsequent… #51
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,17 +243,17 @@ export class BaseService { | |
@nonHTTPRequestMethod | ||
private _resolveHeaders(methodName: string, args: any[]): any { | ||
const meta = this.__meta__; | ||
const headers = meta[methodName].headers || {}; | ||
const headers = { ...meta[methodName].headers }; | ||
const headerParams = meta[methodName].headerParams; | ||
for (const pos in headerParams) { | ||
if (headerParams[pos]) { | ||
if (headerParams[pos] && args[pos] !== undefined) { | ||
headers[headerParams[pos]] = args[pos]; | ||
} | ||
} | ||
const headerMapIndex = meta[methodName].headerMapIndex; | ||
if (headerMapIndex >= 0) { | ||
for (const key in args[headerMapIndex]) { | ||
if (args[headerMapIndex][key]) { | ||
if (args[headerMapIndex][key] !== undefined) { | ||
headers[key] = args[headerMapIndex][key]; | ||
} | ||
} | ||
|
@@ -264,17 +264,17 @@ export class BaseService { | |
@nonHTTPRequestMethod | ||
private _resolveQuery(methodName: string, args: any[]): any { | ||
const meta = this.__meta__; | ||
const query = meta[methodName].query || {}; | ||
const query = { ...meta[methodName].query }; | ||
const queryParams = meta[methodName].queryParams; | ||
for (const pos in queryParams) { | ||
if (queryParams[pos]) { | ||
if (queryParams[pos] && args[pos] !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue 2 - sending undefined as valueOnce leak was fixed, optional params with no value specified would always be present as keys in query config object with value of
This isn't desirable as given the query string For headers this effect was worse as errored due to trying to call Avoiding adding unspecified optional query and header args to config avoids this, so they don't get sent with the request at all |
||
query[queryParams[pos]] = args[pos]; | ||
} | ||
} | ||
const queryMapIndex = meta[methodName].queryMapIndex; | ||
if (queryMapIndex >= 0) { | ||
for (const key in args[queryMapIndex]) { | ||
if (args[queryMapIndex][key]) { | ||
if (args[queryMapIndex][key] !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue 3 - discarding legitimate falsy valuesWhile this bit technically was already preventing |
||
query[key] = args[queryMapIndex][key]; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue 1 - leaking across requests
If method has an
@Queries
decorator,this.__meta__[methodName].query
exists and is pulled in by reference, so when appending new params to the query object these end up being persisted on the instance and so undesirably get pulled into the next request viathis.__meta__[methodName].query
this.__meta__[methodName].query
is only safe for and meant for static query params, cloning the query object before manipulation breaks the reference and fixes this issue