Skip to content

Commit

Permalink
Add Legacy Support for Lico
Browse files Browse the repository at this point in the history
Added Legacy Support for Lico via legacy plugin and added csp headers dynamically in build html.

Related: libregraph#143
  • Loading branch information
soun059 committed Nov 11, 2024
1 parent d829bd9 commit e47f9aa
Show file tree
Hide file tree
Showing 4 changed files with 1,443 additions and 20 deletions.
4 changes: 2 additions & 2 deletions identifier/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func (i *Identifier) writeWebappIndexHTML(rw http.ResponseWriter, req *http.Requ
// FIXME(longsleep): Set a secure CSP. Right now we need `data:` for images
// since it is used. Since `data:` URLs possibly could allow xss, a better
// way should be found for our early loading inline SVG stuff.
rw.Header().Set("Content-Security-Policy", fmt.Sprintf("default-src 'self'; img-src 'self' data:; font-src 'self' data:; script-src 'self'; style-src 'self' 'nonce-%s'; base-uri 'none'; frame-ancestors 'none';", nonce))
rw.Header().Set("Content-Security-Policy", fmt.Sprintf("default-src 'self'; img-src 'self' data:; font-src 'self' data:; script-src 'self' 'nonce-%s'; style-src 'self' 'nonce-%s'; base-uri 'none'; frame-ancestors 'none';", nonce, nonce))

// Write index with random nonce to response.
index := bytes.Replace(i.webappIndexHTML, []byte("__CSP_NONCE__"), []byte(nonce), 1)
index := bytes.ReplaceAll(i.webappIndexHTML, []byte("__CSP_NONCE__"), []byte(nonce))
rw.Write(index)
}

Expand Down
2 changes: 2 additions & 0 deletions identifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.9.0",
"@typescript-eslint/typescript-estree": "^6.11.0",
"@vitejs/plugin-legacy": "^5.3.2",
"@vitejs/plugin-react": "^4.1.1",
"cldr": "^7.4.0",
"eslint": "^8.53.0",
Expand All @@ -60,6 +61,7 @@
"if-node-version": "^1.1.1",
"jsdom": "^22.1.0",
"source-map-explorer": "^2.5.3",
"terser": "^5.30.4",
"typescript": "^5.2.2",
"vite": "^4.5.2",
"vite-plugin-checker": "^0.6.2",
Expand Down
47 changes: 39 additions & 8 deletions identifier/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import react from '@vitejs/plugin-react';
import checker from 'vite-plugin-checker';
import { defineConfig, splitVendorChunkPlugin } from "vite";
import react from "@vitejs/plugin-react";
import checker from "vite-plugin-checker";
import legacy from "@vitejs/plugin-legacy";
import path from "path";


const htmlBuildPlugin = () => {
return {
name: "html-build-plugin",
apply: "build",
transformIndexHtml: {
order: "post",
handler(htmlData) {

return htmlData.replaceAll(
/<script nomodule>/gi,
`<script nomodule nonce="__CSP_NONCE__">`
).replaceAll(
/<script type="module">/gi,
`<script type="module" nonce="__CSP_NONCE__">`
).replaceAll(
/<script nomodule crossorigin id="vite-legacy-entry"/gi,
`<script nomodule crossorigin id="vite-legacy-entry" nonce="__CSP_NONCE__"`
);
},
},
};
};

export default defineConfig((env) => {
return {
Expand All @@ -23,13 +49,18 @@ export default defineConfig((env) => {
},
plugins: [
react(),
env.mode !== 'test' && checker({
typescript: true,
eslint: {
lintCommand: 'eslint --max-warnings=0 src',
},
legacy({
targets: ['edge 18'],
}),
env.mode !== "test" &&
checker({
typescript: true,
eslint: {
lintCommand: 'eslint --max-warnings=0 src',
},
}),
splitVendorChunkPlugin(),
htmlBuildPlugin(),
],
test: {
globals: true,
Expand Down
Loading

0 comments on commit e47f9aa

Please sign in to comment.