Incorrect admin scope mentioned in the UI when a non-admin user creates a personal access token using a crafted request
HackerOne report #1836166 by the_machine_ on 2023-01-16, assigned to @ameyadarshan:
Report | Attachments | How To Reproduce
Report
Summary
On https://gitlab.com/-/profile/personal_access_tokens, a user can create a new personal access token (PAT) for the GitLab API. Thereby the user can select different scopes (e.g. 'api', 'read_api', ...). The page only contains the scopes that are available for the current user. There are two scopes for admins that are not displayed for non-admins. However a non-admin can just manually extends the creation form (HTML) with the scopes for admins and select them as well. If the non-admin submits the creation for with the additional admin scopes, a personal access token is created and the UI shows that PAT having admin scopes (when in fact it does not).
Steps to reproduce
(Step-by-step guide to reproduce the issue, including:)
- Sign in to GitLab as a non-admin.
- Visit https://gitlab.com/-/profile/personal_access_tokens to create a personal access token.
- Extend the checkbox list of scopes with the 'sudo' and 'admin_mode' scopes (scopes for admins only). See this section below on how to do that as a proof-of-concept.
- Check the 'sudo' and 'admin_mode' scopes and submit the form.
- The UI lists that the personal access token has 'sudo' and 'admin_mode' scopes when it fact it does not.
Impact
Incorrect admin scope mentioned in the UI when a non-admin user creates a personal access token using a crafted request. This can lead to confusion on the user end.
What is the current bug behavior?
The selected scopes (from UI) are not validated in the backend.
What is the expected correct behavior?
The selected scopes (from UI) should be validated in the backend. It should be forbidden for non-admins to create a personal access token with scopes for admins.
Relevant logs and/or screenshots
HTML to extend the checkbox list of scopes with the 'sudo' and 'admin_mode' scopes:
<div class="gl-form-checkbox custom-control custom-checkbox">
<input id="personal_access_token_scopes_sudo" data-qa-selector="sudo_checkbox" class="custom-control-input" type="checkbox" value="sudo" name="personal_access_token[scopes][]">
<label data-qa-selector="sudo_label" class="custom-control-label" for="personal_access_token_scopes_sudo"><span>sudo</span><p class="help-text" data-testid="pajamas-component-help-text">Grants permission to perform API actions as any user in the system, when authenticated as an admin user.</p></label>
</div>
<div class="gl-form-checkbox custom-control custom-checkbox">
<input id="personal_access_token_scopes_admin_mode" data-qa-selector="admin_mode_checkbox" class="custom-control-input" type="checkbox" value="admin_mode" name="personal_access_token[scopes][]">
<label data-qa-selector="admin_mode_label" class="custom-control-label" for="personal_access_token_scopes_admin_mode"><span>admin_mode</span><p class="help-text" data-testid="pajamas-component-help-text">Grants permission to perform API actions as an administrator, when Admin Mode is enabled.</p></label>
</div> Output of checks
This bug happens on GitLab.com
Impact
Incorrect admin scope mentioned in the UI when a non-admin user creates a personal access token using a crafted request
Attachments
How To Reproduce
Please add reproducibility information to this section: