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

Improve withApiKey auth middleware #226

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

andrii-balitskyi
Copy link
Contributor

  • Improve withApiKey auth middleware
  • ci: Format code
  • Test

@seambot
Copy link
Contributor

seambot commented Nov 29, 2024

Bundle dist size: 26M

const invalidKeyErr = await t.throwsAsync<SimpleAxiosError>(
axios.get("/devices/list", {
headers: {
Authorization: "Bearer invalid_api_key",

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer invalid_api_key" is used as
authorization header
.
const clientSessionErr = await t.throwsAsync<SimpleAxiosError>(
axios.get("/devices/list", {
headers: {
Authorization: `Bearer seam_cst1_123`,

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer seam_cst1_123" is used as
authorization header
.
const accessTokenErr = await t.throwsAsync<SimpleAxiosError>(
axios.get("/devices/list", {
headers: {
Authorization: `Bearer seam_at_123`,

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer seam_at_123" is used as
authorization header
.
t.is(accessTokenErr?.response.error.type, "access_token_used_for_api_key")

// Test using JWT instead of API key
const token = jwt.sign({ some: "payload" }, "secret")

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "secret" is used as
jwt key
.
Comment on lines +46 to +55
let decodedJwt
try {
decodedJwt = jwt.decode(token)
} catch {}
if (decodedJwt != null) {
throw new UnauthorizedException({
type: "unauthorized",
message: "A JWT was used instead of an API key",
})
}
Copy link
Contributor Author

@andrii-balitskyi andrii-balitskyi Nov 29, 2024

Choose a reason for hiding this comment

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

This block is incorrect in seam-connect but I fixed it here.
In seam-connect it'll never throw when JWT is provided because the error gets always caught being in the try block: https://github.com/seamapi/seam-connect/blob/486c564a7138bca4cd93ce51d6370bee4405fcbd/lib/middlewares/api-key-auth.ts#L54-L61.
Created an issue: https://github.com/seamapi/seam-connect/issues/9520

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.

3 participants