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

jwt_auth plugin extractCredentials: check request content-type #1728

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1728.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix jwt_auth extractCredentials plugin to only try to read credentials from the request body if there is a `Content-Type: application/json` header. @davisagli
15 changes: 8 additions & 7 deletions src/plone/restapi/pas/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ def extractCredentials(self, request):
# Prefer any credentials in a JSON POST request under the assumption that any
# such requested sent when a JWT token is already in the `Authorization` header
# is intended to change or update the logged in user.
try:
creds = deserializer.json_body(request)
except exceptions.DeserializationError:
pass
else:
if "login" in creds and "password" in creds:
return creds
if request.getHeader("Content-Type") == "application/json":
try:
creds = deserializer.json_body(request)
except exceptions.DeserializationError:
pass
else:
if "login" in creds and "password" in creds:
return creds

creds = {}
auth = request._auth
Expand Down