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

Inlined certificates #162

Merged
merged 7 commits into from
Aug 18, 2020
Merged

Inlined certificates #162

merged 7 commits into from
Aug 18, 2020

Conversation

Pimm
Copy link
Collaborator

@Pimm Pimm commented Aug 17, 2020

  1. The certificates are passed as ca instead of cert1.
  2. The certificates are now bundled into the JavaScript files by rollup.js. This makes the library more portable, fixing Client fails to import pem file on AWS lambda #105.

What it looks like to me ‒ and I am not a security expert ‒ is that we are not using the certificates at this time. Instead, we fall back on the certificates included in Node.js.

With this PR, the certificates included in Node.js should be ignored in favour of the ones we provide.

Additionally, we are no longer loading the certificates file from the file system at runtime. This means we are no longer doing a require('fs').

To make our users not shoot themselves in the foot

There is a side-effect. In the current version, (mistakenly) integrating the library in a React app using create-react-app would cause this error:

TypeError: […].readFileSync is not a function

It breaks, because require('fs') doesn't provide the required API. However, this is the very line this PR removes…

Without any extra checks, with this PR merged a developer can call createMollieClient in a React app with no warnings/errors. (This is due to webpack providing a polyfill for https and url. It seems webpack 5 will cease this behaviour, but the current version of webpack still has it.)

This PR includes an extra check, which detects polyfills for https ‒ and hopefully detects integrations in websites or apps that way.

Thoughts

We could choose to rely on certificates included in Node.js (which we are doing now by accident) instead of providing our own list. This means giving up control and trusting Node.js to keep our users safe.

Alternatively, we could choose to only provide the certificate we need (i.e. USERTrust RSA Certification Authority).

Pimm added 3 commits May 29, 2020 15:17
With the certificates file inlined, we no longer depend on require('fs'). This ‒ unfortunately ‒ makes Webpack compile this library to be used in a browser without hesitation. This runtime check should detect frontend integration.
@Pimm
Copy link
Collaborator Author

Pimm commented Aug 17, 2020

Screenshot of error when integrating in React app

It seems to me this library was never using the CA certificates because they were wrongly passed as "cert" instead of "ca". The reason it works despite this, is that Node.js actually bundles their own CA certificates, which were used instead.
@Pimm Pimm marked this pull request as ready for review August 17, 2020 12:33
@vernondegoede vernondegoede self-requested a review August 17, 2020 17:25
@vernondegoede
Copy link
Contributor

I left 1 minor (nitpicky) comment. Thanks for thinking of that case.

Tested this locally, and it works great! Thanks for this nice PR 👏

@vernondegoede vernondegoede merged commit c1be9d3 into master Aug 18, 2020
@vernondegoede vernondegoede deleted the pimm/inlined-cert branch August 18, 2020 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants