Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Introduce CSP policies for GraphQL Playground (#7662)

NyanKiyoshibcd39eeb8eed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 816dff4dbe..52b2a77fae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -286,6 +286,7 @@ All notable, unreleased changes to this project will be documented in this file.
- remove `companyName` on `WarehouseInput` type
- remove `WarehouseAddressInput` on `WarehouseUpdateInput` and `WarehouseCreateInput`, and change it to `AddressInput`
- Fix passing incorrect customer email to payment gateways - #7486 by @korycins
+- Add HTTP meta tag for Content-Security-Policy in GraphQL Playground - #7662 by @NyanKiyoshi
# 2.11.1
diff --git a/saleor/graphql/views.py b/saleor/graphql/views.py
index 1b856f2536..2907be2daa 100644
--- a/saleor/graphql/views.py
+++ b/saleor/graphql/views.py
@@ -113,7 +113,11 @@ class GraphQLView(View):
return response
def render_playground(self, request):
- return render(request, "graphql/playground.html", {})
+ return render(
+ request,
+ "graphql/playground.html",
+ {"api_url": request.build_absolute_uri(str(API_PATH))},
+ )
def _handle_query(self, request: HttpRequest) -> JsonResponse:
try:
diff --git a/templates/graphql/playground.html b/templates/graphql/playground.html
index 8e5b8dffdb..6e750cacd6 100644
--- a/templates/graphql/playground.html
+++ b/templates/graphql/playground.html
@@ -4,12 +4,14 @@
<meta charset=utf-8/>
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
<title>GraphQL Playground</title>
- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/graphql-playground-react/build/static/css/index.css" />
- <link rel="shortcut icon" href="//cdn.jsdelivr.net/npm/graphql-playground-react/build/favicon.png" />
- <script src="//cdn.jsdelivr.net/npm/[email protected]/build/static/js/middleware.js"></script>
+ <link rel="stylesheet" crossorigin="anonymous" integrity="sha256-dKnNLEFwKSVFpkpjRWe+o/jQDM6n/JsvQ0J3l5Dk3fc" href="https://cdn.jsdelivr.net/npm/[email protected]/build/static/css/index.css" />
+ <link rel="shortcut icon" href="https://cdn.jsdelivr.net/npm/[email protected]/build/favicon.png" />
+ <script crossorigin="anonymous" integrity="sha256-24AcA5M3t+KN6ZRQvfqBG51OyLciyk0UJwVBAX94SZI=" src="https://cdn.jsdelivr.net/npm/[email protected]/build/static/js/middleware.js"></script>
+ <meta http-equiv="content-security-policy" content="default-src 'none'; connect-src {{ api_url }}; script-src 'sha256-24AcA5M3t+KN6ZRQvfqBG51OyLciyk0UJwVBAX94SZI=' 'sha256-jpQ7CLb9c8nrwEY+pDfFNOgGpKzrNTRsWVv4yB8QVnQ='; style-src https://cdn.jsdelivr.net/npm/[email protected]/build/static/css/index.css 'sha256-jkwxzyKPdPQHgIYu9x7it0jbIOtzMGr9iFmRtSaiwX4='; img-src data: https://cdn.jsdelivr.net/npm/[email protected]/build/static/media/logo.8c98d067.png https://cdn.jsdelivr.net/npm/[email protected]/build/favicon.png">
</head>
<body>
- <div id="root" {% if api_url %}data-endpoint="{{ api_url }}"{% endif %} {% if query %}data-query="{{ query|safe }}"{% endif %}>
+ <div id="root" data-endpoint="{{ api_url }}" {% if query %}data-query="{{ query|safe }}"{% endif %}>
+ {# sha256-jkwxzyKPdPQHgIYu9x7it0jbIOtzMGr9iFmRtSaiwX4= #}
<style>
body {
background-color: rgb(23, 42, 58);
@@ -37,11 +39,12 @@
font-weight: 400;
}
</style>
- <img src='//cdn.jsdelivr.net/npm/graphql-playground-react/build/logo.png' alt=''>
+ <img src='https://cdn.jsdelivr.net/npm/[email protected]/build/static/media/logo.8c98d067.png' alt=''>
<div class="loading"> Loading
<span class="title">GraphQL Playground</span>
</div>
</div>
+ {# sha256-jpQ7CLb9c8nrwEY+pDfFNOgGpKzrNTRsWVv4yB8QVnQ= #}
<script>window.addEventListener('load', function (event) {
const settings = {
"schema.polling.enable": false