kiwitcms vulnerable to stored XSS via unrestricted files upload
### Impact
Kiwi TCMS allows users to upload attachments to test plans, test cases, etc. Earlier versions of Kiwi TCMS had introduced upload validators in order to prevent potentially dangerous files from being uploaded, see GHSA-fwcf-753v-fgcj
https://github.com/kiwitcms/Kiwi/security/advisories/GHSA-fwcf-753v-fgcj and Content-Security-Policy definition to prevent cross-site-scripting attacks, see GHSA-2wcr-87wf-cf9j
https://github.com/kiwitcms/Kiwi/security/advisories/GHSA-2wcr-87wf-cf9j.
The upload validation checks were not robust enough which left the possibility of an attacker to circumvent them and upload a potentially dangerous file. Exploting this flaw a combination of files could be uploaded so that they work together to circumvent the existing Content-Security-Policy and allow execution of arbitrary JavaScript in the browser.
### Patches
- File upload validation code has been improved
- Kiwi TCMS will now force `Content-Type: text/plain` when serving uploaded files
### Workarounds
1) Force the Content-Type header via a custom Django middleware, see `ExtraHeadersMiddleware` in
https://github.com/kiwitcms/Kiwi/blob/master/tcms/core/middleware.py#L23 and/or
2) Force the Content-Type header via Nginx overrides, see `location /uploads/` in
https://github.com/kiwitcms/Kiwi/blob/master/etc/nginx.conf
### References
Disclosed by Antonio Spataro
https://huntr.dev/bounties/db75275f-8bcd-482b-ae12-feff660d4794 and ek1ng
https://huntr.dev/bounties/46d5b535-bdff-4b98-8691-a907591fcf10/. Additional credits to Ahmed Rabeaa Mosa
https://huntr.dev/bounties/cbc2676a-90ff-457f-9cdc-2a7981f960f3/.