Skip to content

Commit

Permalink
chore: add CSP (Content Security Policy) to demo (#150)
Browse files Browse the repository at this point in the history
- last few PRs made the lib more CSP compliant, this PR simply adds the CSP meta tag to the online demo
  • Loading branch information
ghiscoding authored Nov 7, 2023
1 parent 8bd346b commit 82b5baf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
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.

0 comments on commit 82b5baf

Please sign in to comment.