cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.66k stars 695 forks source link

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

Closed rista404 closed 3 months ago

rista404 commented 11 months ago

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 commented 11 months ago

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?

magick93 commented 7 months ago

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

andyjessop commented 4 months ago

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

reggi commented 4 months ago

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?

penalosa commented 3 months ago

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.

reggi commented 3 months ago

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