workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: `DOMException Imported HMAC key length (0)`

Open rista404 opened this issue 2 years ago • 4 comments

Which Cloudflare product(s) does this pertain to?

Pages, Workers Runtime, Miniflare

What version(s) of the tool(s) are you using?

3.17.0 [Wrangler]

What version of Node are you using?

21.2.0

What operating system are you using?

Mac

Describe the Bug

When running a Remix app that used to work well, now I'm getting the following error:

✘ [ERROR] DOMException {

    stack: 'Error: Imported HMAC key length (0) must be a non-zero value up to 7 bits less than, and no greater than, the bit length of the raw key data (0).\n' +
      '    at createKey2 (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:4029:34)\n' +
      '    at unsign (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:4025:120)\n' +
      '    at decodeCookieValue (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:153:33)\n' +
      '    at Object.parse (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:240:70)\n' +
      '    at Object.getSession (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:3852:61)\n' +
      '    at DashSession.init (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:38297:33)\n' +
      '    at getLoadContext (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:38326:56)\n' +
      '    at file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:29085:45\n' +
      '    at handleFetch (file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:29105:42)\n' +
      '    at async file:///Users/directory/.wrangler/tmp/dev-9DCAmD/zqcotfammqp.js:29109:14',
    code: 0,
    name: 'DataError',
    message: 'Imported HMAC key length (0) must be a non-zero value up to 7 bits less than, and no greater than, the bit length of the raw key data (0).'
  }

[mf:inf] GET / 500 Internal Server Error (5ms)

The same error occurs on Node LTS, and even on wrangler v3.8.0. That's the version I've used previously that worked so I tried to revert but the issue is still there it just has a different error message in the console:

DOMException {
  stack: undefined,
  code: undefined,
  name: undefined,
  message: undefined
[mf:inf] GET / 500 Internal Server Error (8ms)

Not sure what caused the issue, was it the upgrade to the latest version or something else? If it is of any help I'm using Remix v2.0.1 but I'm not sure that is related.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

rista404 avatar Nov 22 '23 13:11 rista404

UPDATE: Immediately after reporting, I saw that I was accessing http://localhost:8789 when getting the errors, but upon trying http://127.0.0.1:8789 everything seems to be working.

I still think this is a bug because one would think that localhost should work, right?

rista404 avatar Nov 22 '23 14:11 rista404

I've tried with both localhost and 127.0.0.1 and get the same error.

magick93 avatar Mar 07 '24 05:03 magick93

Thanks very much for reporting this! Would you be able to provide a minimal reproduction so that we can investigate?

andyjessop avatar Jun 25 '24 09:06 andyjessop

I just saw this error in production using wrangler 3.53.1

{
    "error": "Imported HMAC key length (0) must be a non-zero value up to 7 bits less than, and no greater than, the bit length of the raw key data (0)."
}

What does this mean?

reggi avatar Jun 26 '24 21:06 reggi

We haven't heard from you in while so I'm going to close this issue for now. @rista404 If you're still running into problems feel free to comment with more details & a reproduction, and we can investigate further.

penalosa avatar Jul 08 '24 13:07 penalosa

for future travelers my error was related to env vars not being around and trying to use an empty secret to hash, so check your env vars

reggi avatar Jul 08 '24 20:07 reggi