Reflected XSS in Graphviz PlantUML Diagram
HackerOne report #2796600 by ankitsingh on 2024-10-22, assigned to @kmorrison1:
Report | Attachments | How To Reproduce
Summary
The vulnerability is caused by PlantUML configuration.
It was resolved on GitLab.com by disabling SVG support for PlantUML: gitlab-com/gl-infra/k8s-workloads/tanka-deployments!1084 (merged).
We need to update the documentation to close this issue: #513626 (comment 2346026869).
Report
Background -:
Earlier I reported #2010926 which was about an XSS issue escalated to an Account Takeover scenario by utilizing various methods such as stealing personal access token or forcefully becoming the Admin within the instance etc. CSRF token steal was also possible.
That issue could have been exploited in two manners. One was about Reflected XSS escalated to Account Takeover and other was about Stored XSS escalated to Account Takeover (Yes, the title of that report is wrong, it was not solely a Reflected XSS).
I demonstrated there, that in the Reflected XSS case, a URL would be sent to the user, and once they visit at it and click over the displayed error message then their personal access token will be stolen to the attacker, or attacker will forcefully become the admin of the instance, or their CSRF token will be stolen to attacker, etc. In the Stored XSS case, same consequences would be achieved, only difference was in this case attacker would be a user of the instance having the privilege to edit the Wiki page to include the malicious Graphviz diagram (See the first comment made on June 2, 2023, 3:33pm UTC in that report for the details of Stored XSS exploitation).
I retested the fix on the latest Gitlab version, and found that the team has fixed the Stored XSS method of the issue but not the Reflected XSS method. I mean now it's not possible to edit the Wiki page or any file from the repository to include the malicious Graphviz diagram. But the attack is still possible if the attacker directly sends an URL having the encoded malicious Graphviz diagram. Means, an incomplete fix has been implemented.
Setup -:
Make sure you have enabled your PlantUML integration and is operating properly as documented at https://docs.gitlab.com/ee/administration/integration/plantuml.html. For testing purpose, I've my Gitlab instance running at Debian 11.0.7 at https://192.168.133.139. And a Tomcat 10.1.31 server with PlantUML running at http://192.168.1.16:8080/plantuml. To configure the redirection, I added this line to /etc/gitlab/gitlab.rb -:
nginx['custom_gitlab_server_config'] = "location /-/plantuml { \n rewrite ^/-/(plantuml.*) /$1 break;\n proxy_cache off; \n proxy_pass http://192.168.1.16:8080/plantuml; \n}\n"
Otherwise if you're running Gitlab in Docker then you can configure the integration accordingly as per the doc.
i) Proof of Concept (Plain XSS)
Visit at following URL and click at the displayed error message -:
https://gitlab-instance/-/plantuml/svg/PK-vJWGn3Etv2YiLICCiDJj9jz1G82Ig5OKpziu4lF78a-KGujz9H84GXP-FztnHcWoN6MxXympW9zx7QLHHy-vjJeNTqxPIMObXlywui8_wti5QFeIzCprbOkeEIOJ9TV2_TMQab2VODyqVkWF1oEA7eM0KXgX6NDah1oEB_APXA5QD02LDsJlXGt5XPwO6bt23gUw6eY2ArSzShyY5S-c7Q9jmBunhhKaQNvhAkEdwVjWK2XMiGJiWX0uU7-wyUyPNN4TBIxb6OIldfEFfs0QI7Z7bYsrxxUiR
ii) Proof of Concept (Becoming Admin of the instance)
Visit at following URL and click at the displayed error message -:
https://gitlab-instance/-/plantuml/svg/U9nbK4rFmp0ClVChh1nMa4gxyzhqW3G-f24X1AU9GvfuROQNbDGRcn3_dOHDcX27EBRVyxFrZEs26dguWwyBW6E-R3ljoGSfFdlBADwg23bl49PZhmQKhT_dCFA1K8hWjywWoLUM28t8uVzeZyfOry4oSVx0EP1gaMHTise9eVN1O4Id0ZGIdSkcvX2V0KMsSr8GhbWqyn1yW6kuLJRk1lP0NiM_ntY5OtHSr6qecoT2DSOUMVsUM04JhoZgaaqJGqWX7T0qERm-BwHOgvqQTR03pupNsqsIwf3dX2czEJoOo-pNh6bsLLZdCDo_F2vaDY6kZdF0X-ZKv6FhkMBSStcMF3PX3Fg4zyp3E2lBQ9F1dIgqZvgnsbXNhCSJVT9nbUJBaqWiioeP_7tn0zB0cnq0
Now visit at https://gitlab-instance/admin/users and you will observe a new admin has been added to your instance with the name Ankit Singh, depicting a scenario where an unauthenticated user has become the Admin of the Gitlab instance.
See the attached short PoC video
iii) Proof of Concept (Stealing personal Access token)
Visit at following URL and click at the displayed error message -:
https://gitlab-instance/-/plantuml/svg/U9nbK4rFmp0ClUzNM3ci89LsvxNf0MbyI4D224uJXxJnsWoJbCGRcn3_dOHDcX27EBRVyxFrjEcz6WUuXQy9m35VjNtdo7afFWV3A5wh25cd4LPXK2FArkrp27mWbCAxhTMeyxKXGYro-3yweDB6zh1Ad3zm3gHQ95dNh5f2Q9tN6D6PW0w9pcLJiuzFWoBJMoa8rooQXVVEmnNSA1Dt0piWf-8_OBp2CbekwjQNpIEX2h57fdjBB8-9LnHroRg9mQUG3cYQ75wUbb9ir4w5pfkHvzfrs_SarICl25DwVRZN5zclMRFiiZ3MehzxVbZAR4fS7UU03z6fwSVMSSMuv_8iUMn2yDq97vZ7C2_BQ9F6dIew5pNBmAYes8GJVTfpbUJBaqWiioeP_3tv0TM0coq0
Observe a popup confirming the stolen personal access token. Moreover, if you visit at https://gitlab-instance/-/user_settings/personal_access_tokens then there also you will observe a new personal access token by the name AnkitSingh assigned with the full scope. The token will expire after 1 year.
See the attached short PoC video
iv) Proof of Concept (CSRF token steal)
Though this is not required because obviously to achieve the above two attack scenarios, I had to first steal the CSRF token to further perform stealing of personal access token or adding an Admin user. But anyways, I'm providing here a dedicated PoC separately for stealing the CSRF token of any user within the instance.
Visit at following URL and click at the displayed error message -:
https://gitlab-instance/-/plantuml/svg/U9nbK4rFmp0ClUzNM3ci89Lsv_NZW3G-f24X1AU9GvfuROP9IkADJOZ_Ji8cJOX37Dll-TbwslHUZWFSmjS4u9YlkbuvShuHduDX5AzLXApJ2Aimo16Rpkrp27mWR8HtMwjHvsj3X5hay7zqGAcDxM6LE7_W74XsI4rTi-m8eNDUOqHd0XGIdSksPX-V1accjuqWNBDe5zux3rTm8qtS3Uo0d8p_WF4AosYvg3jVje-4CiGU6VMMM1uJhoZgadKRWqyX7T2sERmyBHknaJiPb3SZpxLJs_SarICl25DwVRZN5zclMRFiiZ3MehzxVbWssPIuEiu17w9Jqu-juufnp-LPyjY4uDK97vZ7C2_BQ9F6dIoKYvgb2dvTRCA9FUsvIkhbIIEMMPNy_Pxy03Otci80
Upon utilizing this URL, observe that you got redirected to evil.com alongwith leaking your CSRF token.
See the attached short PoC video
What is the current bug behavior?
The generic method of enabling PlantUML integration with the self hosted Gitlab instance leads to an XSS vulnerability by rendering Graphviz Diagrams. Consequently, this leads to a full Account Takeover scenario either by inviting an Admin user to the instance or by stealing the personal access tokens or CSRF tokens. Similarly, this XSS could also be escalated to leverage many other different forms of attack scenarios.
What is the expected correct behavior?
XSS should be prohibited by employing proper validation and CSP.
Results of GitLab environment info
System information
System: Debian 11
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 3.1.5p253
Gem Version: 3.5.17
Bundler Version:2.5.11
Rake Version: 13.0.6
Redis Version: 7.0.15
Sidekiq Version:7.2.4
Go Version: unknown
GitLab information
Version: 17.4.2-ee
Revision: e85e7bae1a9
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 14.11
URL: https://192.168.133.139
HTTP Clone URL: https://192.168.133.139/some-group/some-project.git
SSH Clone URL: git@192.168.133.139:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 14.39.0
Repository storages:
- default: unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Gitaly
- default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version: 17.4.2
- default Git Version: 2.46.0 Impact
Full Account Takeover either by forcefully becoming admin of the instance or by stealing personal access token is possible via XSS in Graphviz Diagram. CSRF token steal is also possible. Similarly, this XSS could also be escalated to leverage many other different forms of attack scenarios.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section: