Skip to content
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
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/intermediary.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rems Intermediary UI</title>
<title>PIMS Pharmacy</title>
</head>
<body>
<div id="root"></div>
Expand Down
40 changes: 40 additions & 0 deletions frontend/vite-xss-middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// vite-xss-fix.ts
import { Plugin } from 'vite';

export function viteXssMiddleware(): Plugin {
const middleware = (req: any, res: any, next: any) => {
const originalEnd = res.end;
const chunks: any[] = [];

res.end = function (chunk?: any) {
if (chunk) chunks.push(Buffer.from(chunk));

const body = Buffer.concat(chunks).toString();

// If Vite's error message is reflecting user input, replace it
if (body.includes('did you mean to visit') && body.includes('<a href=')) {
const safe = `<!DOCTYPE html>
<html>
<head><title>404 Not Found</title></head>
<body><h1>404 - Page Not Found</h1></body>
</html>`;
res.setHeader('Content-Type', 'text/html');
return originalEnd.call(res, safe);
}

return originalEnd.call(res, Buffer.concat(chunks));
};

next();
};

return {
name: 'vite-xss-fix',
configureServer(server) {
server.middlewares.use(middleware);
},
configurePreviewServer(server) {
server.middlewares.use(middleware);
}
};
}
5 changes: 2 additions & 3 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

import { viteXssMiddleware } from './vite-xss-middleware';
import dotenv from 'dotenv';

dotenv.config({ path: '.env' }); // load env vars from .env
export default defineConfig({
// depending on your application, base can also be "/"
base: process.env.REACT_APP_VITE_BASE || '',
plugins: [react()],
plugins: [react(), viteXssMiddleware()],
preview: {
allowedHosts: ['.mitre.org', '.elb.us-east-1.amazonaws.com'],
port: parseInt(process.env.PORT!),

Check warning on line 12 in frontend/vite.config.ts

View workflow job for this annotation

GitHub Actions / Check tsc, lint, and prettier on front end

Forbidden non-null assertion

Check warning on line 12 in frontend/vite.config.ts

View workflow job for this annotation

GitHub Actions / Check tsc, lint, and prettier on front end

Forbidden non-null assertion
host: true
},
define: {
'process.env': process.env
},
server: {
port: parseInt(process.env.PORT!),

Check warning on line 19 in frontend/vite.config.ts

View workflow job for this annotation

GitHub Actions / Check tsc, lint, and prettier on front end

Forbidden non-null assertion

Check warning on line 19 in frontend/vite.config.ts

View workflow job for this annotation

GitHub Actions / Check tsc, lint, and prettier on front end

Forbidden non-null assertion
open: false,
host: true,
allowedHosts: ['.mitre.org', '.elb.us-east-1.amazonaws.com']
Expand Down
Loading