-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
9
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
9 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 f9a05dd
Merge branch 'master' into fix/tests-assert-string
jankapunkt aa88382
fix: stricter toString conversion for unsupported types
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,60 @@ | ||
| '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) { | ||
| const type = typeof value; | ||
| if (type === 'string') { | ||
| return value; | ||
| } | ||
|
|
||
| if (type === 'undefined' || value === null) { | ||
| throw new TypeError(`Cannot convert ${value} to a string`); | ||
| } | ||
|
|
||
| if (type === 'number' || type === 'bigint') { | ||
| const val = String(value); | ||
| if (val === 'NaN' || val === 'Infinity' || val === '-Infinity') { | ||
| throw new TypeError(`Invalid numeric value ${value}, cannot be converted to a string (${val})`); | ||
| } | ||
| return val; | ||
| } | ||
|
|
||
|
|
||
| throw new TypeError(`Cannot convert value ${value} of type ${type} to a string`); | ||
| } | ||
|
|
||
| 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.
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.
Uh oh!
There was an error while loading. Please reload this page.