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 special characters in MIQ_GROUP header #287

Merged
merged 1 commit into from
Jan 17, 2018

Conversation

jntullo
Copy link

@jntullo jntullo commented Jan 17, 2018

Non-ASCII characters are not permitted in headers. In our case, we have an X_MIQ_GROUP header that specifies the group description. Our group descriptions allow special characters (as in the case SR-APP-EPM-Membre-équipe, which poses an interesting dilemma.

Headers with special characters get encoded incorrectly (ie, SR-APP-EPM-Membre-\xE9quipe), causing the following error, which does not allow the SUI to proceed with login if the user's current group contains a special character:

ActiveRecord::StatementInvalid: PG::CharacterNotInRepertoire: ERROR:  invalid byte sequence for encoding "UTF8": 0xe9 0x71 0x75
: SELECT  "miq_groups".* FROM "miq_groups" INNER JOIN "miq_groups_users" ON "miq_groups"."id" = "miq_groups_users"."miq_group_id" WHERE "miq_groups_users"."user_id" = $1 AND "miq_groups"."description" = $2 LIMIT $3

Gif to demonstrate before behavior (pretty uneventful):
login_fail_sui

This fix properly encodes it back into UTF8, however, I am on the fence on whether we should allow this, or if group description validation should be changed to not allow special characters (although, may be difficult because groups already exist with special characters).

The following gif demonstrates login working successfully with a user that belongs to a group with a special character:

login_success_sui

Thoughts? @imtayadeway @abellotti @gtanzillo
cc: @AllenBW @yrudman
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1531626#c9

@miq-bot add_label bug, blocker, gaprindashvili/yes

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

Would like @abellotti to review

@jntullo
Copy link
Author

jntullo commented Jan 17, 2018

After discussion with @AllenBW and @imtayadeway - we think that the SUI does not need this header at all, because they now are able to change the current group via set_current_group, and the group header is always just the user's current_group, which is unnecessary to specify. The related SUI pr is: ManageIQ/manageiq-ui-service#1360

@gtanzillo
Copy link
Member

@jntullo Based on your comment, do you think we still need this change to the API?

@jntullo
Copy link
Author

jntullo commented Jan 17, 2018

@gtanzillo I am not sure. If we decide to keep this header available in the API as a way to authenticate against a different group than the user's current_group, then it would make sense that we should fix this in the event that someone does have a special character in their group name and are using this header.

However, I'm not sure that this header is even needed anymore. Users are now able to change their current group ("action": "set_current_group"), and it seems to make more sense that they are authenticated against their current group, not the one specified in the headers. I'll start a discussion in the API gitter room.

I will remove the BZ reference from the commit, though, as I believe the SUI approach is the better solution to that particular bug.

@abellotti
Copy link
Member

Yes, we still need to fix this and keep supporting the header.

@jntullo
Copy link
Author

jntullo commented Jan 17, 2018

@abellotti pushed up another commit that may be a better approach. Perhaps we should require that the header be properly encoded. I tested by properly escaping the header like so:

req['X_MIQ_GROUP'] = CGI.escape('SR-APP-EPM-Membre-équipe')

and it works as expected.

cc: @imtayadeway

@imtayadeway
Copy link
Contributor

Perhaps we should require that the header be properly encoded

Agree. If we must keep compatibility with the current behavior, we shouldn't be trying to work around clients sending non-ASCII characters.

@abellotti
Copy link
Member

Thanks @jntullo for fixing this. Will merge when 🍏

With the MIQ_GROUP header properly escaped, special characters in group descriptions will now be able to be specified.

unescape the group name
@miq-bot
Copy link
Member

miq-bot commented Jan 17, 2018

Checked commit jntullo@2fcc33b with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

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

🎉 Thanks @jntullo !

@abellotti abellotti added this to the Sprint 78 Ending Jan 29, 2018 milestone Jan 17, 2018
@abellotti abellotti merged commit e89fc56 into ManageIQ:master Jan 17, 2018
simaishi pushed a commit that referenced this pull request Jan 18, 2018
Fix special characters in MIQ_GROUP header
(cherry picked from commit e89fc56)

https://bugzilla.redhat.com/show_bug.cgi?id=1536047
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 9cbb5d91f4db9ce0fd855c06ddf7b2dcd1f593d6
Author: Alberto Bellotti <abellotti@users.noreply.github.com>
Date:   Wed Jan 17 15:28:25 2018 -0500

    Merge pull request #287 from jntullo/bz_1531626
    
    Fix special characters in MIQ_GROUP header
    (cherry picked from commit e89fc56e6a6be50447fe61c210f254843c61eb6d)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1536047

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

Successfully merging this pull request may close these issues.

None yet

6 participants