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: Unable to log in with third-party apps without "Manage OAuth Apps" permission #32782

Closed

Conversation

verdel
Copy link

@verdel verdel commented Jul 13, 2024

Added a new REST API method oauth-apps.info that returns a limited set of attributes (clientId, name) necessary for rendering the consent screen

Proposed changes (including videos or screenshots)

The issue is detailed in my comment on the #31749 .

The attributes clientId and name of the OAuth application are used in the process of rendering the consent screen. The API method oauth-apps.get is used to obtain these attributes. This method also returns the clientSecret attribute.

To prevent regular users from obtaining this sensitive data, the user must have manage-oauth-apps permissions to call the method. Therefore, regular users cannot use the third-party login process.

I am adding a separate API method oauth-apps.info that only returns the clientId and name attributes needed in the process of rendering the consent screen.

Issue(s)

Closes #31749

CORE-473

@verdel verdel requested review from a team as code owners July 13, 2024 10:49
Copy link

changeset-bot bot commented Jul 13, 2024

🦋 Changeset detected

Latest commit: 0edac8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 32 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/api-client Patch
@rocket.chat/ddp-client Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/models Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Jul 13, 2024

CLA assistant check
All committers have signed the CLA.

@verdel verdel force-pushed the fix-oauth-flow-for-non-privileged-user branch from 7f9cc44 to 918fe12 Compare July 14, 2024 21:32
…Auth Apps permission

Added a new REST API method oauth-apps.info that returns a limited set
of attributes (clientId, name) necessary for rendering the consent screen

Signed-off-by: Vadim Aleksandrov <[email protected]>
@verdel verdel force-pushed the fix-oauth-flow-for-non-privileged-user branch from 918fe12 to e87d8d5 Compare July 14, 2024 21:34
Copy link
Member

@matheusbsilva137 matheusbsilva137 left a comment

Choose a reason for hiding this comment

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

Thanks for creating this PR! 🚀 I'll bring this for our team to check too

apps/meteor/tests/end-to-end/api/oauthapps.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.28%. Comparing base (851d60a) to head (ce358c0).

❗ There is a different number of reports uploaded between BASE (851d60a) and HEAD (ce358c0). Click for more details.

HEAD has 8 uploads less than BASE
Flag BASE (851d60a) HEAD (ce358c0)
e2e 10 2
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #32782      +/-   ##
===========================================
- Coverage    55.66%   48.28%   -7.39%     
===========================================
  Files         2637     2219     -418     
  Lines        57399    50179    -7220     
  Branches     11892    10268    -1624     
===========================================
- Hits         31954    24231    -7723     
- Misses       22731    23843    +1112     
+ Partials      2714     2105     -609     
Flag Coverage Δ
e2e 38.28% <ø> (-16.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@verdel verdel force-pushed the fix-oauth-flow-for-non-privileged-user branch from 474fa7d to ce358c0 Compare July 30, 2024 09:09
@verdel
Copy link
Author

verdel commented Jul 30, 2024

@matheusbsilva137, I also fixed the type errors that were discovered after running the GitHub Workflow.

@verdel verdel requested a review from matheusbsilva137 July 30, 2024 09:17
@matheusbsilva137 matheusbsilva137 added this to the 6.12 milestone Jul 30, 2024
Copy link
Contributor

dionisio-bot bot commented Jul 30, 2024

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 6.12.0, but it targets 6.11.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@matheusbsilva137 matheusbsilva137 changed the title fix: Restore ability to log in with third-party apps without Manage OAuth Apps permission fix: Unable to log in with third-party apps without "Manage OAuth Apps" permission Jul 30, 2024
{ authRequired: true, validateParams: isOauthAppsInfoParams },
{
async get() {
const oauthApp = await OAuthApps.findOneAuthAppByIdOrClientId(this.queryParams);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a projection since you're returning just clientId/name

Copy link
Contributor

Choose a reason for hiding this comment

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

(this will imply updating the model typings for allowing the projection to go as the current method doesn't allow it)

Copy link
Author

Choose a reason for hiding this comment

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

I added projection to the findOneAuthAppByIdOrClientId method of the IOAuthAppsModel and OAuthAppsRaw models. I hope I changed the code everywhere it was needed and didn't forget anything.

apps/meteor/tests/end-to-end/api/oauthapps.ts Show resolved Hide resolved
Comment on lines 1 to 4
export interface IOAuthAppsInfo {
clientId: string;
name: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Personal pref: do we need this to be an interface? Can't we just export type OauthAppsInfo = Pick<IOAuthApps, 'clientId' | 'name'> ?

Copy link
Author

Choose a reason for hiding this comment

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

I agree, that will be better.

Also added a check for the case when the OAuthApp is not found
@verdel verdel force-pushed the fix-oauth-flow-for-non-privileged-user branch from 18dbc0f to c3348d7 Compare July 30, 2024 21:51
@verdel
Copy link
Author

verdel commented Aug 2, 2024

@matheusbsilva137, sorry for the inconvenience, but I added a commit to fix the Prettier warning that appeared during code linting in the GitHub workflow. The tests need to be run again.

@verdel verdel requested a review from MarcosSpessatto August 2, 2024 19:33
@matheusbsilva137
Copy link
Member

Hey @verdel !
I brought the solution proposed by this PR for the consideration of our team (internally) and we considered that a new endpoint to fix this specific issue may be too much since the current endpoint can be adapted to return only proper info based on user permission. Due to this decision, I created #32986, which we'll use to fix this issue
Thanks for contributing and for bringing this issue to us. Please check #32986 to be aware of the next steps regarding this fix (we'll push this so that this fix can be included in 6.12)

@verdel
Copy link
Author

verdel commented Aug 5, 2024

@matheusbsilva137, I'm sorry that I initially went a bit off track. In my comment on the issue, I mentioned two possible ways to solve the problem: modifying the oauth-apps.get method or adding a new method.

@scuciatto's comment eventually led me to choose the second option. And I still lean towards the idea that using a separate method (which returns the minimal necessary number of OAuth App attributes) within the OAuth2 Authorization Flow, regardless of user permissions, is a more correct approach from a security perspective, even though it might be less correct from an API method semantics standpoint.

In any case, if the core product development team has decided that the solution proposed in your PR is more appropriate, then I can't influence that decision. At least I was able to help in some way with the final implementation of the idea. Moreover, your solution addresses the original problem mentioned in the issue.

Thank you and everyone who reviewed this PR for your time.

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.

Third-Party Login only works for user with "Manage Oauth Apps"-permission.
5 participants