Skip to content

feat: Add OIDC Salt service#64

Merged
matias-gonz merged 14 commits intofeat/oidc-account-recoveryfrom
oidc/salt-service
Feb 13, 2025
Merged

feat: Add OIDC Salt service#64
matias-gonz merged 14 commits intofeat/oidc-account-recoveryfrom
oidc/salt-service

Conversation

@matias-gonz
Copy link
Member

Description

Additional context

Copy link

@calvogenerico calvogenerico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left several comments, but the most important one it's the combination of the values using JSON. I believe we have to go a little bit stronger there.

"@vueuse/nuxt": "^11.1.0",
"@wagmi/core": "^2.13.3",
"@wagmi/vue": "^0.0.49",
"axios": "^1.7.9",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about just using fetch? I believe we are not doing anything fancy with the requests, It's basically a GET request. I believe we can avoid adding a dependency here.

"@wagmi/vue": "^0.0.49",
"axios": "^1.7.9",
"jsonwebtoken": "^9.0.2",
"jwk-to-pem": "^2.0.7",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked jose? It's a library created by auth0 that I believe it's kind of the standard for jwt manipulation.

With jose you can use directly the JWK instead of having to convert to PEM:

https://github.com/panva/jose/blob/HEAD/docs/jwt/verify/functions/jwtVerify.md
https://github.com/panva/jose/blob/HEAD/docs/key/import/functions/importJWK.md

'https://accounts.google.com',
'accounts.google.com',
];
const SALT_ENTROPY = process.env.SALT_ENTROPY || 'entropy';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this kind of services I like to have a "secure" default. Defaulting to an usecure string means that if we have a typo when we set this variable we are going to deploy with an unsecure value. I believe it's better to just throw if the value is missing.

const aud = verifiedToken.aud;
const sub = verifiedToken.sub;

const data = { iss, aud, sub , entropy: SALT_ENTROPY };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON it's kind of not deterministic enough for this. Different implementations might serialize keys in different order.

I believe a better approach is to treat the values as buffers and then concatenate them together. But if you do that you need to be careful about uniqueness of the keys generated. The easiest way to achieve this is by prefixing each chunk with the size, or using some separator that are sure that it's not present in the chunks that you are merging.

return jwkToPem(jwk);
}

export default defineEventHandler(async (event) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have thought how we can test this?

@matias-gonz matias-gonz merged commit 1c7092c into feat/oidc-account-recovery Feb 13, 2025
1 of 3 checks passed
@matias-gonz matias-gonz deleted the oidc/salt-service branch February 13, 2025 14:33
cpb8010 pushed a commit that referenced this pull request Jul 16, 2025
* Add salt endpoint

* Verify JWT

* Add hash salt

* Add hash salt

* Update packages/auth-server/server/api/salt.ts

* Lint

* lint

* Remove axios

* Remove axios

* Make SALT_ENTROPY required

* Use jose

* Encode data in buffer

* Crop salt
cpb8010 pushed a commit that referenced this pull request Jul 16, 2025
* Add salt endpoint

* Verify JWT

* Add hash salt

* Add hash salt

* Update packages/auth-server/server/api/salt.ts

* Lint

* lint

* Remove axios

* Remove axios

* Make SALT_ENTROPY required

* Use jose

* Encode data in buffer

* Crop salt
cpb8010 pushed a commit that referenced this pull request Jul 16, 2025
* Add salt endpoint

* Verify JWT

* Add hash salt

* Add hash salt

* Update packages/auth-server/server/api/salt.ts

* Lint

* lint

* Remove axios

* Remove axios

* Make SALT_ENTROPY required

* Use jose

* Encode data in buffer

* Crop salt
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

Successfully merging this pull request may close these issues.

2 participants