Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add CSP (Content Security Policy) to demo #150

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self';style-src 'self' 'unsafe-inline' data:; img-src * 'self' data: https:; require-trusted-types-for 'script'; trusted-types dompurify">
<title>Multiple-Select-Vanilla demo with Vite + TS</title>
</head>
<body>
Expand Down
2 changes: 2 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"dependencies": {
"@popperjs/core": "^2.11.8",
"bootstrap": "^5.3.2",
"dompurify": "^3.0.6",
"font-awesome": "^4.7.0"
},
"devDependencies": {
"@types/dompurify": "^3.0.4",
"multiple-select-vanilla": "workspace:*",
"sass": "^1.69.5",
"typescript": "^5.2.2",
Expand Down
9 changes: 7 additions & 2 deletions demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap';
import 'font-awesome/css/font-awesome.css';
import DOMPurify from 'dompurify';
import { createDomElement, emptyElement } from 'multiple-select-vanilla';

import { exampleRouting, navbarRouting } from './app-routing';
Expand Down Expand Up @@ -32,7 +33,9 @@ class Main {

async init() {
const location = window.location;
document.querySelector<HTMLDivElement>('#app')!.innerHTML = mainHtml;
document.querySelector<HTMLDivElement>('#app')!.innerHTML = DOMPurify.sanitize(mainHtml, {
RETURN_TRUSTED_TYPE: true,
}) as unknown as string;

let route = location.hash.replace(this.stateBangChar, '');
if (!route || route === '/' || route === '#') {
Expand Down Expand Up @@ -121,7 +124,9 @@ class Main {
if (foundRouter) {
this.currentRouter = foundRouter;
// const html = await import(/*@vite-ignore*/ `${foundRouter.view}?raw`).default;
document.querySelector('.panel-wm-content')!.innerHTML = pageLayoutGlobs[foundRouter.view];
document.querySelector('.panel-wm-content')!.innerHTML = DOMPurify.sanitize(pageLayoutGlobs[foundRouter.view], {
RETURN_TRUSTED_TYPE: true,
}) as unknown as string;
const vm = new foundRouter.viewModel() as ViewModel;
this.currentModel = vm;
(window as any)[foundRouter.name] = vm.mount?.();
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.