Skip to content

Commit

Permalink
Don't treat numbers larger than the JS max number size as number valu…
Browse files Browse the repository at this point in the history
…es in environment variables (directus#6119)

* Incorrect parsing of numeric values in env.

* Fixes incorrect parsing of the env. file with numeric values that are outside of Number.MAX_SAFE_INTEGER resulting in unwanted behaviour.
- Like wrong client_ids for oauth. (tested with discord oauth)
* Removed unnecessary multiple "IF" statements since value can only be ether one of the listed values.

* Implements custom_param for OAUTH via grant

According to grants documentation you can provide additionally custom parameters to supported OAUTH provider with ```custom_params```.
This change allows to add them in JSON format and thus adding multiple parameters.

* Fix linter warnings, remove JSON support in favor of nested Grant support

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
  • Loading branch information
skizer and rijkvanzanten authored Jun 9, 2021
1 parent 792281c commit ad8bd3e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions api/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,16 @@ function processValues(env: Record<string, any>) {
}

if (value === 'true') env[key] = true;
if (value === 'false') env[key] = false;
if (value === 'null') env[key] = null;
if (String(value).startsWith('0') === false && isNaN(value) === false && value.length > 0) env[key] = Number(value);
else if (value === 'false') env[key] = false;
else if (value === 'null') env[key] = null;
else if (
String(value).startsWith('0') === false &&
isNaN(value) === false &&
value.length > 0 &&
value < Number.MAX_SAFE_INTEGER // Make sure we don't treat long numeric ID strings as numbers
) {
env[key] = Number(value);
}
}

return env;
Expand Down

0 comments on commit ad8bd3e

Please sign in to comment.