swagger-api / swagger-api/swagger-ui

CSP error due to inline style

Open
#10,655 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: Windows 11
  • Browser: tested with chrome and edge
  • Version: 142.0.7444.176 (Chrome), 143.0.3650.66 (Edge)
  • Method of installation: dist assets
  • Swagger-UI version: 5.30.3
Content & configuration

Swagger-UI configuration options:

  window.ui = SwaggerUIBundle({
    urls: [
      <redacted>
    ],
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl,
      SwaggerUIBundle.plugins.Topbar
    ],
    displayOperationId: false,
    defaultModelsExpandDepth: 1,
    defaultModelRendering: "example",
    displayRequestDuration: false,
    docExpansion: "list",
    filter: false,
    operationsSorter: "alpha",
    showExtensions: false,
    tagsSorter: "alpha",
    validatorUrl: "none",
    apisSorter: "alpha",
    jsonEditor: false,
    showRequestHeaders: false,
    supportedSubmitMethods: [
      "get", "put", "post", "delete", "options", "head", "patch", "trace"
    ],
    layout: "StandaloneLayout"
  });

  window.ui.initOAuth({
    useBasicAuthenticationWithAccessCodeGrant: true,
    realm: "<redacted>"
  })
Describe the bug you're encountering

On loading the page an error is given in the developer console:

Applying inline style violates the following Content Security Policy directive 'style-src 'self''. Either the 'unsafe-inline' keyword, a hash ('sha256-RL3ie0nH+Lzz2YNqQN83mnU0J1ot4QL7b99vMdIX99w='), or a nonce ('nonce-...') is required to enable inline execution. The action has been blocked.

Line 2, column 245529 of swagger-ui-bundle.js

swagger-ui-bundle.js:2 Applying inline style violates the following Content Security Policy directive 'style-src 'self''. Either the 'unsafe-inline' keyword, a hash ('sha256-RL3ie0nH+Lzz2YNqQN83mnU0J1ot4QL7b99vMdIX99w='), or a nonce ('nonce-...') is required to enable inline execution. The action has been blocked.
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
Vj @ swagger-ui-bundle.js:2
ek @ swagger-ui-bundle.js:2
dk @ swagger-ui-bundle.js:2
ck @ swagger-ui-bundle.js:2
dk @ swagger-ui-bundle.js:2
Wk @ swagger-ui-bundle.js:2
Pk @ swagger-ui-bundle.js:2
Gk @ swagger-ui-bundle.js:2
J @ swagger-ui-bundle.js:2
R @ swagger-ui-bundle.js:2
To reproduce...

Steps to reproduce the behavior:

  1. Set up Swagger UI on a site that blocks inline styles through the use of CSP
  2. Load Swagger UI
  3. An error is shown in the console
Expected behavior

That Swagger UI can be used together with a Content Security Policy that doesn't allow inline scripts or styles.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the dist swagger-ui-bundle.js assets under a style-src 'self' CSP, then inspect the reported location in swagger-ui-bundle.js. Done means Swagger UI loads and remains usable without a CSP console error for a blocked inline style.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.