Fix XSS vulnerabilities in swh-web
Related T1699
Differential D1442
swh-web: Fix XSS kalpitk on May 4 2019, 5:09 PM. Authored by
Details
Fix XSS vulnerabilities in swh-web Related T1699
Diff Detail
Event TimelineComment Actions Build is green Comment Actions My main issue on that change is that the generated links will not be available anymore in the displayed error message, see output below after your change on that example (https://archive.softwareheritage.org/browse/revision/041f5ea1cf987a4068ef5f39ba0a09be85952064/?origin=https://github.com/git/got): swh.web.common.exc.NotFoundExc: The Software Heritage archive has a revision with the hash you provided but the origin mentioned in your request appears broken: <a href="https://github.com/git/got">https://github.com/git/got</a>. Please check the URL and try again. Nevertheless, you can still browse the revision without origin information: <a href="/browse/revision/041f5ea1cf987a4068ef5f39ba0a09be85952064/">/browse/revision/041f5ea1cf987a4068ef5f39ba0a09be85952064/</a> This makes the navigation more painful as the user will have to copy / paste the link instead of simply clicking on it. Considering the only vulnerability here is if someone submits an origin url through a save code now request containing <script> tags in it, I think it will be better to filter out that kind Comment Actions @anlambert Comment Actions @kalpitk , indeed this is not so easy as it seems to fix any possible XSS injections.
Yes, this calls for clever filtering server-side on the submitted origin urls to save into the archive.
Maybe but at least the harmful tags will be removed so this is not really a big deal IMHO. We should really add some end to end tests using Selenium in a near future to better detect Comment Actions Build is green Comment Actions Looks good. Please address my comment and I will accept the diff.
Comment Actions @anlambert We need to remember to use 'escape' unsafe things, whenever marking some html as safe. I think, I'll add selenium end-to-end tests in another commit (as per Timeline in my GSoC proposal?) Comment Actions Build is green Comment Actions Build is green Comment Actions Build is green Comment Actions
Indeed, can you create a task on the forge to track this work ?
Of course, adding end-to-end tests should be handled in a separate diff and a task should also be created on the forge (maybe I already created one, need to check that).
Comment Actions @kalpitk , I found other XSS vulnerabilities related to error pages. In the file common/exc.py, request.META['PATH_INFO'] values must also be escaped (see https://forge.softwareheritage.org/source/swh-web/browse/master/swh/web/common/exc.py$71 as an example). Also, every message set to the following exception types: NotFoundExc, BadInpuExc, ForbiddenExc in the browse code should be checked for url escaping (see https://forge.softwareheritage.org/source/swh-web/browse/master/swh/web/browse/views/utils/snapshot_context.py$80-120 for instance) Can you add these extra url escaping to that diff ? Comment Actions
Comment Actions Build is green Comment Actions Build is green Comment Actions @anlambert I think, I have added escape wherever it was vulnerable. checksums and ids and plain strings can't have xss vulnerability. Comment Actions Build is green
Comment Actions @kalpitk , found another issue in the web api HTML interface: http://localhost:5004/api/1/origin/git/url/%3Cscript%3Ealert(document.domain)%3C/script%3E/ You should fix that by hacking on api/apiresponse.py
Comment Actions Looks like we need to escape branch names too, nice catch!
Comment Actions Build has FAILED Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/429/
Comment Actions @kalpitk , I found where the XSS vulnerability is located when a branch name contains some HTML code in it. In the file templates/includes/top-navigation.html, you need to replace: var snapshotContext = false; var branch = false; {% if snapshot_context %} snapshotContext = true; branch = {{ snapshot_context.branch|jsonify }}; {% endif %} swh.browse.initSnapshotNavigation(snapshotContext, branch); by var snapshotContext = false; var branch = false; {% if snapshot_context %} snapshotContext = true; branch = "{{ snapshot_context.branch|escape }}"; {% endif %} swh.browse.initSnapshotNavigation(snapshotContext, branch !== "None"); Comment Actions Build is green Comment Actions @kalpitk , I think we fixed most of the XSS vulnerabilities so I am ready to accept the diff in its current state.
swh-web: Fix numerous XSS vulnerabilities detail the issues fixed in the commit message body then terminate the commit message with that line Closes T1699
Comment Actions Build is green Comment Actions Thanks for the deep testing for XSS ! Let's land this. You should be able to push your changes to the master branch using git directly (use the Phabricator web interface otherwise). |