10 points · by jwally · 2y ago · 14 comments
const db = await openDatabase();
const keyPair = await getKeyPair(db);
await crypto.subtle.exportKey("jwk", keyPair.privateKey)
exports the private key if I have a XSS vuln.The recommendation for IP address in the JWT is good, but I don't understand your last recommendation of 1) sending the JWT, 2) additionally sending the base64 JWT in a header 3) sending the signature in the header. The crypto.subtle api only works on https domains so you're not defending against mitm attacks on unsecure networks either. And if we can't trust TLS what can we trust on the web?
So here I'm basically trying to describe what changes you would make to the way JWT validation is currently done. IIRC, the JWT goes over in the headers. I'm suggesting adding 2 headers - one with the base64 of the json of the JWT, the other header is the ecdsa signature of that.
This way, you know whoever it is that logged in and provided their signed public key, has to be sending this request because they signed it with the same key - which is locked to _this_ browser.
But I think ideally I would use a wrapped JWT with `"alg": "ES256"` and just pass it as normal in a bearer token[0] as JWTs natively support signed primitives.
[0]: https://jwt.io/#debugger-io?token=eyJhbGciOiJFUzI1NiIsInR5cC...
I think you're right. Just sign the JWT that's going over as a header (as its a string), and add a signature from the webcrypto pieces - and BAM! you can verify that the jwt came from who it was originally assigned to...unless I'm missing something.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/Credential_...
If it can store live objects - its perfect.
IDB is neat because it can store a PrivateKey Object whose `extractable` attribute has been set to false. So when you try to see the crypto data, you cannot.
Serves me right having ChatGPT add commentary and me not double checking.
This is what it should be:
const keyPair = await crypto.subtle.generateKey(
{ name: "ECDSA", namedCurve: "P-256" },
false, // this makes it not extractable
["sign", "verify"]
);
Run that in HTTPS (here if you want) and try to extract the private key - I don't think you can, but could be wrong.I'd love to see IDPs adopt the concept. Coupled with passkeys; it seems like it would be extremely difficult to break into someone else's account (not impossible, but this definitely adds an order or 2 of difficulty)