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

Cypress invalid proxy certificate affects disk cache #7307

Closed
jsantha opened this issue May 12, 2020 · 28 comments
Closed

Cypress invalid proxy certificate affects disk cache #7307

jsantha opened this issue May 12, 2020 · 28 comments
Labels
browser: chromium existing workaround stage: ready for work The issue is reproducible and in scope stale no activity on this issue for a long period type: unexpected behavior User expected result, but got another

Comments

@jsantha
Copy link

jsantha commented May 12, 2020

Current behavior:

Information that certificate error is purely cosmetic problem as specified here docs.cypress.io/faq/questions/using-cypress-faq.html is misleading.

Chrome, as reported here bugs.chromium.org/p/chromium/issues/detail?id=110649 ignores http caching when any error with ssl certificate occurs. This means that the application under the test is affected and not behaving as intended (http caching is fully disabled, app load time can be significantly slower...).

Desired behavior:

  1. Inform about this potential problem in FAQ
  2. Maybe inform that this problem can be resolved by importing CypressProxyCA from cy/production/proxy/certs/ca.pem to the Trusted Root Certification Authority store

Test code to reproduce

https://github.com/jsantha/cypress-invalid-cert

Versions

Chrome from version ~16 to actual (81)
Windows 10
Cypress 4.5.0

@jsantha jsantha changed the title Cypress proxy certificate is not purely cosmetic problem Cypress proxy certificate is not purely a cosmetic problem May 12, 2020
@flotwig
Copy link
Contributor

flotwig commented May 14, 2020

This means that the application under the test is affected and not behaving as intended (http caching is fully disabled, app load time can be significantly slower...).

Have you been able to observe this behavior in Cypress? I have not noticed cache behaving oddly, but it's possible I have not been working on enough HTTPS stuff to see it. We do pass arguments to Chrome to force them to permit invalid certs, so it could also be affecting this behavior.

I ask because this comment seems to imply that caching DOES work, but it is in-memory, not written to disk.


Maybe inform that this problem can be resolved by importing CypressProxyCA from cy/production/proxy/certs to the Trusted Root Certification Authority store

Hmm, this would technically work, but some users will not want Cypress to touch their CA store. Also, this will probably break in any managed environment with antivirus/GPO setups that prevent malicious CAs being installed.

It would be a security issue too. Although the test runner's CA keys are not shared pubicly (they are generated locally per-computer and cached), it's possible that malware on a user's computer could read the CA file and use it to intercept HTTPS traffic without the user's knowledge (if Cypress were added to the CA store)

@jsantha
Copy link
Author

jsantha commented May 14, 2020

I ask because this comment seems to imply that caching DOES work, but it is in-memory, not written to disk.

Quick peek into chromium source code shows that this behavior (cache not work with invalid cert) is intended and cannot be prevented with browser arguments: /net/http/http_cache_transaction.cc

Anyway, I have made a quick test:

Chrome 81
Windows 10
Cypress 4.5.0

  1. invalid certificate = no caching

image

  1. trusted certificate = caching works as expected

image

Our application leverages http caching for some quite heavy REST API calls and since I have rewritten some of our e2e tests from Selenium to Cypress, I have immediately noticed that Cypress test cases run much slower than those running via Selenium.

It would be a security issue too. Although the test runner's CA keys are not shared pubicly (they are generated locally per-computer and cached), it's possible that malware on a user's computer could read the CA file and use it to intercept HTTPS traffic without the user's knowledge (if Cypress were added to the CA store)

I'm not really familiar with internal working of those certificates and theirs potential security issues but we could perhaps inspire at .NET Core SDK that provides a CLI option to make its own development certificate trusted Trust the ASP.NET Core HTTPS development certificate on Windows and macOS and in addition, we could inform users about the potential security risk you mentioned.

@jennifer-shehane
Copy link
Member

Can you provide the full repo/code for your reproduction of the caching issue?

I was not able to verify the behavior that caching is effected from within Cypress when SSL certificate errors are present.

The cache is cleared in Cypress before each run of a spec file. So there will not be any caching on the first run of a test, but the subsequent runs of tests, resources should be cached.

You can observe this with the following test:

it('test', () => {
 cy.visit('https://reactjs.org/docs/getting-started.html')
});
 
it('test2', () => {
 cy.visit('https://reactjs.org/docs/getting-started.html')
});

When looking at the network tab (filtering by Img), the first test has the 'search.svg' with a 200 status. The second test, the request has the 'search.svg' return as status 304 Not Modified. It is returning with the cached image.

Screen Shot 2020-05-15 at 4 33 32 PM copy

@jsantha
Copy link
Author

jsantha commented May 15, 2020

@jennifer-shehane You have chosen wrong file to check caching, the search.svg has max-age=0 and utilizing etag - this request always hits the server but skips response download when etag matches (304). I created a disk cache scenario here https://github.com/jsantha/cypress-invalid-cert

@jennifer-shehane
Copy link
Member

Yeah, it does seem that the invalid certificate will affect disk cache. Thanks for providing the repo.

We could maybe fix this by implementing the certificate override at the remote debugger protocol level (if Chromium’s comment is true).

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label May 21, 2020
@jennifer-shehane jennifer-shehane added the type: unexpected behavior User expected result, but got another label May 21, 2020
@jennifer-shehane jennifer-shehane changed the title Cypress proxy certificate is not purely a cosmetic problem Cypress invalid proxy certificate affects disk cache May 21, 2020
@MichelleSNG20
Copy link

I am using cypress 7.1 and facing this invalid certificate issue.

Should I take this as solution "Maybe inform that this problem can be resolved by importing CypressProxyCA from cy/production/proxy/certs to the Trusted Root Certification Authority store"

Can anyone please advise how to access this 'cy/production/proxy/certs'? thanks

@valter11111
Copy link

valter11111 commented May 21, 2021

I agree with the original post, this is not only the cosmetic problem. Chromium browsers also block webRTC access (media devices are disabled) if there is "Not secure" connection.

Using Cypress 7.3

@valter11111
Copy link

@jsantha

  1. Maybe inform that this problem can be resolved by importing CypressProxyCA from cy/production/proxy/certs to the Trusted Root Certification Authority store

I tried this solution, but certificate
image

But chrome still suggests its "Not secure" connection.
image

@jsantha
Copy link
Author

jsantha commented May 21, 2021

@valter11111
I've just tried this workaround again for latest cypress version and it still works, follow these steps:

  • import AppData/Roaming/Cypress/cy/production/proxy/certs/ca.pem
  • restart chrome (check for no background chrome processes in task manager)
  • run tests again and invalid cert warning should disappear

@sara444
Copy link

sara444 commented Jan 16, 2022

@valter11111 I've just tried this workaround again for latest cypress version and it still works, follow these steps:

  • import AppData/Roaming/Cypress/cy/production/proxy/certs/ca.pem
  • restart chrome (check for no background chrome processes in task manager)
  • run tests again and invalid cert warning should disappear

In addition to the above steps, you also need to clear the Site Settings, Data etc using Ctrl+Shift+Delete (on windows) while chrome is openned via Cypress. Otherwise, chrome keeps caching the trust (untrusted certificate) as usual.

@karlamieses
Copy link

  • AppData/Roaming/Cypress/cy/production/proxy/certs/ca.pem

how can I import AppData/Roaming/Cypress/cy/production/proxy/certs/ca.pem @valter11111

@flotwig
Copy link
Contributor

flotwig commented Jun 16, 2022

This should no longer be an issue on the latest version of Cypress, is anyone experiencing this on 10.1.0?

@karlamieses
Copy link

This should no longer be an issue on the latest version of Cypress, is anyone experiencing this on 10.1.0?

I having the following issue with Cypress latest versions when running in the CI, I thought this is related to the issue we are talking here, what do you think?

[1119:0616/211249.791930:ERROR:cert_verify_proc_builtin.cc(681)] CertVerifyProcBuiltin for dashboard.stripe.com failed:
--
620 | ----- Certificate i=0 (OU=Cypress Proxy Server Certificate,O=Cypress Proxy CA,L=Internet,ST=Internet,C=Internet,CN=dashboard.stripe.com) -----
621 | ERROR: No matching issuer found

@shammlo
Copy link

shammlo commented Sep 15, 2022

@flotwig, my Cypress version is "cypress": "^10.8.0", and im still having this error, still receiving "Not secure".

@andrii-lundiak
Copy link

andrii-lundiak commented Jan 21, 2023

I've recently migrated from Cypress v7.x to v9.7.0 and this issue (ERROR: No matching issuer found) happens on my CI only (Azure, Ubuntu). Sometimes it's NOT happening.

I read a few threads and it seems issue was fixed in v10.2.0 which I anticipate to upgrade yet. @MichaelDimmitt refers here: #22128

But I also see that @shammlo refers above to v10.8.0 as also not working version.

@jsantha, as author of this issue which is still open in Jan-2023, how about you?

@awerlang
Copy link

@flotwig @karlamieses @andrii-lundiak I believe the issue you have in mind is unrelated (ERROR: No matching issuer found)

If Cypress could import the ca.pem file automatically, it would improve the experience running on the cloud.

@amenk
Copy link

amenk commented May 5, 2023

  • Would it work to deploy an own valid certificate via https://docs.cypress.io/guides/references/client-certificates or does client certificates really mean client here and has no effect on the cypress proxy-server?
  • What is the path of AppData/Roaming/Cypress/cy/production/proxy/certs/ca.pem on Linux?
    ** EDIT: it's ~/.config/Cypress/cy/production/proxy/certs/ca.pem
  • It can be imported at chrome://settings/certificates -> Authorities in any chrome instance (it seems to be globally trusted than even Cypress uses another User Profile)
  • I can confirm that importing that certificate solves the cache Problems in Cypress with Chrome 113

@nagash77
Copy link
Contributor

nagash77 commented May 5, 2023

Are folks on this thread still experiencing this issue on the latest version of Cypress?

@nagash77 nagash77 self-assigned this May 5, 2023
@amenk
Copy link

amenk commented May 5, 2023

We see the issue in Cypress 12.11.0

@martin-pikalek
Copy link

martin-pikalek commented May 5, 2023

Importing CA certificate solved caching issue for me for local testing but could someone help me, how could I import same certificate in CICD within cypress docker image environment?

Also could be this solved somehow globally within cypress app @jennifer-shehane ? Seems that this issue is known for nearly 3 years and disabled disk cache may quite hard affect testing speeds for apps where developers intentionally utilise browser client cache to speed up loading of assets and reduce HTTP traffic.

@amenk
Copy link

amenk commented May 10, 2023

@martin-pikalek maybe something like this could work https://thomas-leister.de/en/how-to-import-ca-root-certificate/
And yes, it would be good if this would be in the cypress/browsers docker images.

@amenk
Copy link

amenk commented May 11, 2023

The Chrome Cert file to import to seems to be /root/.pki/nssdb/cert9.db I am wondering if Cypress' ca.pem is always generated freshly and we need to import it after running cypress the first time or we could incude it statically in the Docker image.

EDIT: I am trying to prepend something like this to my run command:

        - docker-compose run cypress "yarn cypress install && apt update && apt install -y libnss3-tools && certutil -A -n Cypress -t 'TCu,Cu,Tu' -i /root/.config/Cypress/cy/production/proxy/certs/ca.pem -d sql:/root/.pki/nssdb/ && yarn cypress run --browser $BROWSER --spec cypress/e2e/index.cy.js"

but getting

certutil: function failed: SEC_ERROR_BAD_DATABASE: security library: bad database.

Also we might need to run cypress with an empty spec at first to generate the pa.pem

EDIT2: I have to remove the file name

-d sql:/root/.pki/nssdb works

@amenk
Copy link

amenk commented May 12, 2023

That's the final command we use as a workaround in our CI:

      - $COMPOSE_CMD run cypress bash -c "yarn cypress install && touch cypress/e2e/empty.cy.js && yarn cypress run --browser $BROWSER --spec cypress/e2e/empty.cy.js || true && apt update && apt install -y libnss3-tools && certutil -A -n Cypress -t 'TCu,Cu,Tu' -i /root/.config/Cypress/cy/production/proxy/certs/ca.pem -d sql:/root/.pki/nssdb && yarn cypress run --browser $BROWSER --spec $SPEC"

Are there chances to add an option --auto-import-ca to cypress ?

@marktnoonan
Copy link
Contributor

Glad you got a work around @amenk! --auto-import-ca seems like a good idea to me, would you mind opening a feature request issues linking back to this comment and the other context in this thread? It will help keep the request separate from the longer conversation in this issue.

@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 Nov 19, 2023
@amenk
Copy link

amenk commented Nov 20, 2023

Okay, can be followed up in #26744 then

@cypress-app-bot cypress-app-bot removed the stale no activity on this issue for a long period label Nov 21, 2023
@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 May 19, 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 Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser: chromium existing workaround stage: ready for work The issue is reproducible and in scope stale no activity on this issue for a long period type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests