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

chore(401-when-jwt-token-is-missing): Returns 401 when jwt is missing or not parsable #45

Merged
merged 2 commits into from
Dec 13, 2024

Conversation

papey
Copy link
Member

@papey papey commented Dec 3, 2024

Context 🧐

This PR change the behavior when JWT is not present or not parsable as a JWT token, other error later in the chain, when you have a JWT in hand are not modified.

Changes ⛏️

Returns a 401 when the request does not contains a valid JWT token (valid: present & at least parsable)

@papey papey self-assigned this Dec 3, 2024
Copy link
Contributor

@achouippe achouippe left a comment

Choose a reason for hiding this comment

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

Should we use something more specific like 422 Unprocessable Content ?

@papey
Copy link
Member Author

papey commented Dec 3, 2024

Should we use something more specific like 422 Unprocessable Content ?

The HTTP 422 Unprocessable Content client error response status code indicates that the server understood the content type of the request content, and the syntax of the request content was correct, but it was unable to process the contained instructions.

so i would say the 400 is better for the not parsable token. The only thing bothering me is 400 for missing JWT, i prefer a 401 for this.

@papey
Copy link
Member Author

papey commented Dec 3, 2024

We will go for 401 when no token, 403 when token expired.

@papey papey force-pushed the 400-when-jwt-token-is-missing branch from 30f520b to f23862c Compare December 4, 2024 11:03
@papey papey requested a review from achouippe December 4, 2024 11:03
@papey papey force-pushed the 400-when-jwt-token-is-missing branch from f23862c to b31ccff Compare December 4, 2024 11:06
@papey papey changed the title chore(400-when-jwt-token-is-missing): Returns 400 when jwt is missing or not parsable chore(401-when-jwt-token-is-missing): Returns 401 when jwt is missing or not parsable Dec 4, 2024
@papey papey merged commit d908e39 into main Dec 13, 2024
5 checks passed
@papey papey deleted the 400-when-jwt-token-is-missing branch December 13, 2024 09:51
"JWT authentication error: #{error_code} - #{error_message}, path: '#{conn.request_path}'",
category: "security",
error_code: "jwt_authentication.#{error_code}",
authorization_header: conn |> get_req_header("authorization") |> List.first(),
Copy link
Contributor

@achouippe achouippe Dec 16, 2024

Choose a reason for hiding this comment

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

@papey the authorization_header metadata is not automatically added to json logs. The header should be added directly to the error message, and maybe neurow/lib/neurow/ecs_log_formatter.ex should be updated to add the authorization header in the JSON payload (while ensuring it conforms to the ECS log format)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants