Skip to content

[rest] Fix content-security-policy violation issue on RestCatalog API#5340

Merged
JingsongLi merged 4 commits intoapache:masterfrom
liyubin117:redoc-js
Mar 25, 2025
Merged

[rest] Fix content-security-policy violation issue on RestCatalog API#5340
JingsongLi merged 4 commits intoapache:masterfrom
liyubin117:redoc-js

Conversation

@liyubin117
Copy link
Copy Markdown
Contributor

@liyubin117 liyubin117 commented Mar 25, 2025

Purpose

Apache refuses to load the https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js script due to Content Security Policy (CSP) restrictions. We could import the file, and it also makes loading faster.
As mentioned in Redocly/redoc#1191, we should disable search to avoid

Refused to create a worker from 'blob:http://localhost:1313/5cb97201-bf84-45b4-ae92-3814a5085396' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'". Note that 'worker-src' was not explicitly set, so 'script-src' is used as a fallback.

javascript file refer to https://cdn.jsdelivr.net/npm/redoc@2.0.0/bundles/redoc.standalone.js

Tests

API and Format

Documentation

@liyubin117 liyubin117 marked this pull request as draft March 25, 2025 06:42

docs/assets/github.css (css generated by Hugo) from https://github.com/alecthomas/chroma version 2
docs/static/js/anchor.min.js from https://github.com/bryanbraun/anchorjs version 5.0
docs/static/js/redoc.standalone.js from https://github.com/Redocly/redoc version 2.0.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add its license to licenses directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

<redoc spec-url="https://raw.githubusercontent.com/apache/paimon/master/paimon-open-api/rest-catalog-open-api.yaml"></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"></script>
<div id="redoc-container"></div>
<script src="/docs/master/js/redoc.standalone.js"></script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer it just like "{{.Site.BaseURL}}/js/flink.js"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After setting <script src="{{.Site.BaseURL}}/js/redoc.standalone.js"></script>, throw following error:

GET http://localhost:1313/docs/master/concepts/rest/rest-api/%7B%7B.Site.BaseURL%7D%7D/js/redoc.standalone.js net::ERR_ABORTED 404 (Not Found)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add this <script to head.html, and this file just refer js function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea~

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

@liyubin117 liyubin117 marked this pull request as ready for review March 25, 2025 07:45
@JingsongLi
Copy link
Copy Markdown
Contributor

+1

@JingsongLi JingsongLi merged commit a5aeaa2 into apache:master Mar 25, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants