-
-
Notifications
You must be signed in to change notification settings - Fork 56
Security: explicit string requirement for request parameters (client id, tokens etc.) #399
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
Open
jankapunkt
wants to merge
7
commits into
master
Choose a base branch
from
fix/tests-assert-string
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4a14f4
fix(tests): make required params strings
jankapunkt c76e4c0
refactor: use param-util for parameter type checks and conversions
jankapunkt 11de06a
fix(tests): make compliance tests mixed using db ids as numbers and s…
jankapunkt f3d77ad
fix: support number and strings for id params but pass original param…
jankapunkt 50adf11
fix: rename jsDoc comment model name on param-util.js
jankapunkt e51fc27
fix(test): use string based id in one compliance test for coverage
jankapunkt 802546a
fix(tests): add missing tests for missing and invalid codes in Author…
jankapunkt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * @module ParamUtil | ||
| */ | ||
|
|
||
| /** | ||
| * Create a function to check, whether a value is one of the given types. | ||
| * @param types {...string[]} | ||
| * @return {function(*): boolean} | ||
| */ | ||
| function isInTypes (...types) { | ||
| return function (value) { | ||
| return types.includes(typeof value); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Check if a value is defined (not missing) | ||
| * @param value | ||
| * @return {boolean} | ||
| */ | ||
| function isDefined (value) { | ||
| // TODO: in future versions, consider changing this to `value !== undefined && value !== null && value !== ''`, | ||
| // which might be a breaking changes for some users | ||
| return !!value; | ||
| } | ||
|
|
||
| /** | ||
| * Safely converts a value to a string in the following order: | ||
| * - If the value is already a string, return it. | ||
| * - If the value has a `toString` method, call it and return the result. | ||
| * - If the value is `null` or `undefined`, return an empty string. | ||
| * - Otherwise, use the global `String` function to convert the value. | ||
| * @param value {*} | ||
| * @return {string} | ||
| */ | ||
| function toString(value) { | ||
| if (typeof value === 'string') { | ||
| return value; | ||
| } | ||
|
|
||
| if (Object.prototype.hasOwnProperty.call(value, 'toString')) { | ||
| return value.toString(); | ||
| } | ||
|
|
||
| if (value === null || value === undefined) { | ||
| return ''; | ||
| } | ||
|
|
||
| return String(value); | ||
| } | ||
|
|
||
| module.exports = { isInTypes, isDefined, toString }; | ||
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
Oops, something went wrong.
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.
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.
I think this is too permissive because it will allow objects, arrays, etc to be stringified in a way that we don't want (eg:
{} => [object Object],[] => ""and so on).Also
toString(undefined)causes an error to be thrown.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.
@dhensby let's collect a little spec, before further coding:
undefined,null→''(empty string)string→stringnumber→number.toString()(what to do withNaNandInfinity?BigInt→bigInt.toString()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.
IMO: If it's not a scalar value I'd throw, plus boolean should probably throw. Numbers that are NaN or Infinity should also be rejected. For
undefinedornull, I'm not sure what the behaviour should be, I suppose that depends on context. If we have a body that does not have a value (eg:body.client_secret) and that isundefinedI don't think we should be coercing that into a string, but then again maybe that's a check that should be upstream of this utility.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.
For null and undefined I would personally throw, because these values are not expected to reach this method as they should always be handled prior with respective "Missing xyz" error.