Title: Calling crypto.createCipheriv with a key of invalid length can cause errors in other consumers of the OpenSSL error queue · Issue #21281 · nodejs/node · GitHub
Open Graph Title: Calling crypto.createCipheriv with a key of invalid length can cause errors in other consumers of the OpenSSL error queue · Issue #21281 · nodejs/node
X Title: Calling crypto.createCipheriv with a key of invalid length can cause errors in other consumers of the OpenSSL error queue · Issue #21281 · nodejs/node
Description: Version: v9.3.0 (initially discovered on v8.x but seems relevant to later versions too) Platform: Windows 64-bit + ArchLinux 64-bit Subsystem: Crypto N.B. What follows is a naive speculation about what's going wrong since I'm not all too...
Open Graph Description: Version: v9.3.0 (initially discovered on v8.x but seems relevant to later versions too) Platform: Windows 64-bit + ArchLinux 64-bit Subsystem: Crypto N.B. What follows is a naive speculation about ...
X Description: Version: v9.3.0 (initially discovered on v8.x but seems relevant to later versions too) Platform: Windows 64-bit + ArchLinux 64-bit Subsystem: Crypto N.B. What follows is a naive speculation about ...
Opengraph URL: https://github.com/nodejs/node/issues/21281
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Calling crypto.createCipheriv with a key of invalid length can cause errors in other consumers of the OpenSSL error queue","articleBody":"* **Version**: v9.3.0 (initially discovered on v8.x but seems relevant to later versions too)\r\n* **Platform**: Windows 64-bit + ArchLinux 64-bit\r\n* **Subsystem**: Crypto\r\n\r\nN.B. What follows is a naive speculation about what's going wrong since I'm not all too familiar with Node.js' internals.\r\n\r\nWhen `crypto.createCipheriv` is called, it sets the key length using `EVP_CIPHER_CTX_set_key_length`. For some ciphers this will fail if it doesn't match a certain length. The crypto module throws a JS error if this is the case. If you look at the OpenSSL code for `EVP_CIPHER_CTX_set_key_length`, this error also goes into the OpenSSL error queue but is never removed by the Crypto module.\r\n\r\nBecause this error queue seems to be thread-global, you can get into situations where other stuff using OpenSSL (such as HTTPS/TLS) can think that the error was caused by its actions, not by a stale error being on the queue. Like so:\r\n\r\n```js\r\n// This example shows how having a invalid key length call to createCipheriv\r\n// caught and ignored while a TLS request is going on can cause the TLS request to fail,\r\n// even though the error is completely separate from the TLS connection.\r\nconst crypto = require('crypto');\r\nconst https = require('https');\r\n\r\nsetInterval(() => {\r\n // Internally set_key_length is called but the error it produces (using EVPErr) isn't thrown away quick enough.\r\n try {\r\n crypto.createCipheriv('aes-256-ctr', 'bad key', crypto.randomBytes(16));\r\n } catch (err) {\r\n console.log(err.message);\r\n\r\n // Do nothing so that we continue with the old error on the OpenSSL error queue.\r\n // It would be there anyway, but in normal usage it would be more obvious why things are breaking because\r\n // you would never try/catch the createCipheriv. That's how this issue was discovered.\r\n }\r\n}, 50);\r\n\r\nconst options = {\r\n hostname: 'google.com',\r\n port: 443,\r\n path: '/',\r\n method: 'GET'\r\n};\r\n\r\nconst req = https.request(options, (res) => {\r\n console.log('statusCode:', res.statusCode);\r\n console.log('headers:', res.headers);\r\n\r\n res.on('data', (d) => {\r\n process.stdout.write(d);\r\n });\r\n});\r\n\r\nreq.on('error', (err) => {\r\n // throws the EVPErr produces by createCipheriv.\r\n // At some point the Node.js TLS stack (possibly during TLS read)\r\n // throws the error off the OpenSSL error queue.\r\n throw err;\r\n});\r\n\r\nreq.end();\r\n```\r\n\r\nObviously this is a bad way to use `createCipheriv`, but it seems almost certainly wrong for the error to leak outside of the cipher code. Weirdly enough it seems like something else is pulling out the errors on its own, but if you create enough of them (hence the low ms `setInterval`) then it produces the error.","author":{"url":"https://github.com/z0w0","@type":"Person","name":"z0w0"},"datePublished":"2018-06-12T09:40:04Z","url":"https://github.com/nodejs/node/issues/21281"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:53095a4e-2bdf-a630-5f58-8d93d0cd322b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8CA:373A8C:1F02A7:279C04:6B033DCD |
| html-safe-nonce | 4bfd378fb8a6d0a1c4e1859ecfb6b7d31634446ee621bbb62e03196e09b9f6a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOENBOjM3M0E4QzoxRjAyQTc6Mjc5QzA0OjZCMDMzRENEIiwidmlzaXRvcl9pZCI6IjYxMjM1NTEwMzI4MTY2NDc2MjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1ba6160aba2b841de2900672b3168d43c16327b11603717a6ac7bd192ed17a2e |
| hovercard-subject-tag | issue:331512672 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/21281/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8cae552f02746730534302d0421e2139b86a50ded1269591651feb4d0c041e7b/nodejs/node/issues/21281 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8cae552f02746730534302d0421e2139b86a50ded1269591651feb4d0c041e7b/nodejs/node/issues/21281 |
| og:image:alt | Version: v9.3.0 (initially discovered on v8.x but seems relevant to later versions too) Platform: Windows 64-bit + ArchLinux 64-bit Subsystem: Crypto N.B. What follows is a naive speculation about ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | z0w0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width