Skip to content

Commit

Permalink
fix(config): filter npm_ env
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 21, 2021
1 parent 80e3e6a commit 42a846e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/usage/private-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ For instructions on this, see the above section on encrypting secrets for the Wh

Self-hosted users can use environment variables to configure the most common types of `hostRules` for authentication.

The format of the environment variables must be all upper-case and follow:
The format of the environment variables must follow:

- Datasource name (e.g. `NPM`, `PYPI`)
- Underscore (`_`)
Expand All @@ -227,6 +227,8 @@ The format of the environment variables must be all upper-case and follow:
Hyphens (`-`) in datasource or host name must be replaced with double underscores (`__`).
Periods (`.`) in host names must be replaced with a single underscore (`_`).

Note: the following prefixes cannot be supported for this functionality: `npm_config_`, `npm_lifecycle_`, `npm_package_`.

#### npmjs registry token example

`NPM_REGISTRY_NPMJS_ORG_TOKEN=abc123`:
Expand Down
6 changes: 6 additions & 0 deletions lib/config/env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ describe(getName(), () => {
};
expect(env.getConfig(envParam).hostRules).toHaveLength(0);
});
it('rejects npm env', () => {
const envParam: NodeJS.ProcessEnv = {
npm_package_devDependencies__types_registry_auth_token: '4.2.0',
};
expect(env.getConfig(envParam).hostRules).toHaveLength(0);
});
it('supports Bitbucket token', () => {
const envParam: NodeJS.ProcessEnv = {
RENOVATE_PLATFORM: PLATFORM_TYPE_BITBUCKET,
Expand Down
6 changes: 6 additions & 0 deletions lib/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ export function getConfig(env: NodeJS.ProcessEnv): GlobalConfig {

const hostRules: HostRule[] = [];

const npmEnvPrefixes = ['npm_config_', 'npm_lifecycle_', 'npm_package_'];

for (const envName of Object.keys(env).sort()) {
if (npmEnvPrefixes.some((prefix) => envName.startsWith(prefix))) {
logger.trace('Ignoring npm env: ' + envName);
continue; // eslint-disable-line no-continue
}
// Double underscore __ is used in place of hyphen -
const splitEnv = envName.toLowerCase().replace('__', '-').split('_');
const hostType = splitEnv.shift();
Expand Down

0 comments on commit 42a846e

Please sign in to comment.