swagger-api / swagger-api/swagger-ui
oathRedirect defines an Inline Event Handler which prevents oauth2 login if CSP is set to script-src 'self'
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Hi there!
Q&A
- OS: Windows 10
- Browser: edge/chrome/firefox
- Version: edge79, chrome78, firefox70
- Method of installation: npm
- Swagger-UI version: 3.23.8
- Swagger/OpenAPI version: 3.0
Content & configuration
Configuration
- on the hosting site/app set the Content-Security-Policy: script-src 'self';
- add hashes of the known inline scripts to the CSP otherwise the index page will not load, there are 3 or 4 inline scripts used by swagger that needs to be white listed.
- configure swagger to use oauth2 with implicit flow(okta can be configured as a test oath server)
Describe the bug you're encountering
We are implementing CSP rules on a site hosting the swagger UI. The oauth-redirect.html has an inline event handler that is not possible to white list using CSP Options.
To reproduce...
Steps to reproduce the behavior:
- navigate to swagger index
- click authorize
- login at Idp, you are redirected back to oath-redirect.html
- View Browser Console Error:
CSP Error: Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' 'sha256-hQoyAYxxdlQX6mYg//3SgDUdhiDx4sZq5ThHlCL8Ssg=' 'sha256-wSMjdhDGsmL8uer6UgaOodrMBixq2O/zf4+5e/MFH0A=' 'sha256-eGAYk6fd1okMa1sD6UOTFlv8sY5fE/9GBBbK/dRq+HU='". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
Expected behavior
Redirect should work with csp script-src 'self'
The inline event handler (onload="run()") should be moved to the script block so the entire block can be whitelisted with a hash. E.g.
document.addEventListener("DOMContentLoaded", function(){
run();
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with dist/oauth2-redirect.html at the linked inline onload handler. Reproduce the OAuth2 implicit-flow redirect with Content-Security-Policy: script-src 'self', then inspect the existing script block and verify the redirect works without an inline event handler. Done means the OAuth2 redirect succeeds under that CSP configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- authentication, frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100