Skip to content
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

npm_config_proxy & npm_config_https_proxy are applied but npm_config_noproxy is ignored #27746

Closed
akcyp opened this issue Sep 5, 2023 · 11 comments
Labels
stale no activity on this issue for a long period

Comments

@akcyp
Copy link

akcyp commented Sep 5, 2023

Current behavior

Page specified in baseURL cannot be loaded because of proxy settings specified in global npm config - noproxy setting seems to be ignored

Desired behavior

Cypress should load npm_config_noproxy settings as well.

Test code to reproduce

NPM with any proxy settings. For example:

npm config set proxy http://proxy.company.com:80
npm config set https-proxy http://proxy.company.com:80
npm config set noproxy 10.0.1.32

baseURL set to https://10.0.1.32/ (application working on local network)

Cypress Version

10.11.0 (but probably on latest too)

Node version

v16.16.0

Operating System

Ubuntu 18.04.6 LTS

Debug Logs

No response

Other

https://github.com/cypress-io/cypress/blob/v13.1.0/packages/server/lib/util/proxy.ts#L61
Probably following line should be added:

['npm_config_noproxy', 'NO_PROXY'],
@nagash77
Copy link
Contributor

nagash77 commented Sep 5, 2023

Hi @akcyp In order to give our engineers the best chance at recreating your problem, please create a reproducible example using a fork of Cypress Test Tiny. This gives us the best chance of seeing exactly what you are seeing and being able to investigate effectively.

@nagash77 nagash77 self-assigned this Sep 5, 2023
@MikeMcC399
Copy link
Contributor

@akcyp

You may want to check if you have written baseUrl correctly in your implementation. baseURL as it is written here in the issue is not correct - see https://docs.cypress.io/guides/references/configuration#e2e.

@akcyp
Copy link
Author

akcyp commented Sep 7, 2023

@MikeMcC399 yeah, you are right - I meant baseUrl, not baseURL

@nagash77 I provided steps how you can reproduce it - just use any (working) proxy settings in your npm config and use local IP as baseUrl (instead of localhost)

The problem here is general - cypress takes part of configuration from npm - https://github.com/cypress-io/cypress/blob/v13.1.0/packages/server/lib/util/proxy.ts#L61
Only npm_config_proxy and npm_config_https_proxy is used, but in npm there is also npm_config_noproxy (equalivement to NO_PROXY env variable). https://docs.npmjs.com/cli/v9/using-npm/config#noproxy

I was able to fix this problem by manually setting the NO_PROXY to 10.0.1.32, but that's not the case - I see some inconsistency here - some config is taken from npm config, while some needs to be explicitly specified in env variables, that's the reason why I created this ticket.

@nagash77
Copy link
Contributor

nagash77 commented Sep 8, 2023

@akcyp what is the use case for this setting?

@akcyp
Copy link
Author

akcyp commented Sep 8, 2023

@nagash77 Sorry, I don't understand which setting you are asking about, what is unclear to you?

@nagash77
Copy link
Contributor

Hi @akcyp I am trying to understand what you are using the npm_config_noproxy setting for. The more context around what this potential bug is preventing users from doing the better decisions we can make around its priority.

@akcyp
Copy link
Author

akcyp commented Sep 14, 2023

@nagash77 Ok, let's start with npm_config_* environment variables. According to npm docs (https://docs.npmjs.com/cli/v8/using-npm/config#environment-variables) we can override single npm config by using npm_config_ prefix (so it works similar to npm config set ...). But there is one more usage of this - when we execute npm or npx command all configurations will be loaded into process.env.npm_config_[key].

Take a look on this example:

# package.json
{
  "name": "sample-node-project",
  "version": "1.0.0",
  "scripts": {
    "start": "node"
  }
}

We will be executing this command to see all proxy related configurations:

console.log(Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith('npm_config_') && key.includes('proxy'))))

with single command it would be:

 node -e "console.log(Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith('npm_config_') && key.includes('proxy'))))"

Firstly let's create npm configuration for corporate proxy:

npm config set proxy http://proxy.company.com:80
npm config set https-proxy http://proxy.company.com:80
npm config set noproxy 10.0.1.32

Output for node -e "..." and for npm run start -- -e "...":
image

As we can observe - when using npm (same with npx) npm configuration properties are loaded into npm_config_ env. variables.

To verify that this is not coming from outsite, let's remove configuration and run this script again.
image


From my research cypress under the hood is loading HTTP_PROXY, HTTPS_PROXY, NO_PROXY system wide enviroment variables (as specified in https://docs.cypress.io/guides/references/proxy-configuration), but also (which is not specified in docs) is using npm proxy configuration as fallback values. See here: https://github.com/cypress-io/cypress/blob/v13.1.0/packages/server/lib/util/proxy.ts#L61

The problem I'm describing here is about npm_config_noproxy which seems to be ignored by cypress (while npm_config_proxy and npm_config_https_proxy are loaded - see source code link above).

Real usecase for this?

I have a cypress project that needs to have proxy configuration to access some pages available only through vpn / proxy. I'm not using system HTTP_PROXY, etc. envs. but simply I have proper configuration in .npmrc.

Because of this bug I have to move noproxy config from .npmrc to system NO_PROXY enviroment variable. Not a big deal but seems like inconsistency, not mentioning about spending some hours debugging this 😄. noproxy is very important because without this setting we cannot specify which urls should be ignored by proxy (like my baseUrl 10.0.1.32).

Hope this is clear now. If you have any other questions, fell free to ask.

@bdellegrazie
Copy link

See also #19586

@agreedSkiing
Copy link

As said in #19586 (comment) this is is still an in 12.13.0 issue where the npm config set noproxy values are not merged into the cypress total noproxy configuration for cypress. And even when upgrading to 13.6.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Jul 30, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests

6 participants