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

Fix support of JSON body in /store-invite requests #170

Merged
merged 1 commit into from
Jul 9, 2019

Conversation

babolivier
Copy link
Contributor

The spec says that /store-invite requests should be done using the application/json mimetype, but currently Sydent chokes on such requests, because it first extracts its params from the request, doing the right thing if the content-type is JSON, but, when trying to compute the dict of substitutions to apply to the email template, looks for them in request.args, which is empty when using application/json.

On top of that, json.dumps() outputs a dict which keys and string values are of type unicode, which Python 2 doesn't consider to be strings (or at least not the same as str), so the arguments wouldn't be added to the substitutions dict.

This bug went unnoticed because Synapse isn't compliant with the spec here and sends that data using the application/x-www-form-urlencoded mimetype. This is tracked in matrix-org/synapse#5634.

This makes Sydent not try to re-extract the params from the request.args, but instead use the ones it has already extracted the right way. It also changes the type comparison on the params' values, comparing them with six.string_types instead of only the str type.

The spec says that /store-invite requests should be done using the 'application/json' mimetype, but currently Sydent chokes on such requests, because it first extracts its params from the request, doing the right thing if the content-type is JSON, but, when trying to compute the dict of substitutions to apply to the email template, looks for them in request.args, which is empty when using 'application/json'.

On top of that, json.dumps() outputs a dict which keys and string values are of type 'unicode', which Python 2 doesn't consider to be strings (or at least not the same as 'str'), so the arguments wouldn't be added to the substitutions dict.

This bug went unnoticed because Synapse isn't compliant with the spec here and sends that data using the 'application/x-www-form-urlencoded' mimetype. This is tracked in matrix-org/synapse#5634.

This makes Sydent not try to re-extract the params from the request.args, but instead use the ones it has already extracted the right way. It also changes the type comparison on the params' values, comparing them with six.string_types instead of only the 'str' type.
@babolivier babolivier requested a review from a team July 8, 2019 13:08
@babolivier
Copy link
Contributor Author

babolivier commented Jul 8, 2019

FTR I tested these changes on a personal box, and they work both when the HS sends the request with a application/json content-type and when it does with a application/x-www-form-urlencoded one.

@babolivier
Copy link
Contributor Author

(I wonder if this mandates a new release of Sydent)

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

LGTM. And yes, I think a sydent release is overdue.

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