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

Argon2 not able to be repackaged #337

Closed
bplies-ATX opened this issue Feb 28, 2022 · 3 comments
Closed

Argon2 not able to be repackaged #337

bplies-ATX opened this issue Feb 28, 2022 · 3 comments

Comments

@bplies-ATX
Copy link

bplies-ATX commented Feb 28, 2022

Pretty much an identical situation as #261 with the same symptom and solution except that webpack is not involved. In this case argon2 is imported into a private library to handle multiple kinds of hashes. That library, in turn, is imported into other applications.

Similarity to #261

As with #261 replacing

const binary = require('node-pre-gyp')
const path = require('path')
const bindingPath = binary.find(path.resolve(path.join(__dirname, './package.json')))

const { hash: _hash, limits, types, names, version } = require(bindingPath) /* eslint-disable-line */

with

const { hash: _hash, limits, types, names, version } = require("argon2/lib/binding/napi-v3/argon2.node")

Fixes the issue.

Difference from #261

Unlike #261 webpack isn't involoved so adding

  externals: {
    "argon2": "argon2",
  },

to webpack.config.js isn't an option to fix the issue.

Possible Workarounds

Aside from an actual fix into this codebase...

  • Impose webpack where it isn't otherwise needed
  • Make a custom-patched version of argon2 with the code change we know works
  • Use the argon2-ffi library instead - which is less-frequently maintained and doesn't appear to support argon2id mode.

Steps to reproduce

  1. Create a module that imports argon2 without webpack
  2. Import that new module into an application without webpack
  3. Try running the application

Expected behaviour

It should presumably work.

Actual behaviour

Error: Cannot find module '/[....]/node_modules/argon2/package.json'
    at webpackEmptyContext (/[....]/packages/server/.webpack/service/dist/src/webpack:/[....]/node_modules/node-pre-gyp/lib sync:2:1)
    at Object.module.exports.../../node_modules/node-pre-gyp/lib/pre-binding.js.exports.find (/[....]/packages/server/.webpack/service/dist/src/webpack:/[....]/node_modules/node-pre-gyp/lib/pre-binding.js:20:23)
    at Object.<anonymous> (/[....]/packages/server/.webpack/service/dist/src/webpack:/[....]/node_modules/argon2/argon2.js:8:1)
    at Object.../../node_modules/argon2/argon2.js (/[....]/packages/server/.webpack/service/dist/src/serverless.js:31908:30)
    at __webpack_require__ (/[....]/packages/server/.webpack/service/dist/src/webpack:/webpack/bootstrap:19:1)

Environment

Operating system: OSX Catalina 10.15.7

Node version: 16.9.1

Compiler version:

@ranisalt
Copy link
Owner

ranisalt commented Mar 1, 2022

Aha, I can see what is happening there now. I'm not sure the code is equivalent, I'll give a read to the source code of npg to check.

@ranisalt
Copy link
Owner

ranisalt commented Mar 1, 2022

Thanks for the extensive report!

@bplies-ATX
Copy link
Author

bplies-ATX commented Mar 1, 2022

Astonishing resolution time! I'll try out the new tag as soon as possible.

EDIT: I'm pleased to report that all is well! Thanks a bunch!

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

No branches or pull requests

2 participants