Skip to content

Commit a8acabd

Browse files
committed
fix(socratiq): loop strip in vite dev injector
Single-pass replace can leave overlapping matches re-formed (e.g. <scrip<script ...></script>t...></script>). Iterate until stable so the dev-server injector never serves a half-stripped script tag. Input is the package's own on-disk HTML, so this is defense-in-depth rather than a live exploit, but it clears the CodeQL alert. Closes CodeQL #108.
1 parent 39336c4 commit a8acabd

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

socratiq/vite.config.dev.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,14 @@ export default defineConfig({
175175
// Remove ANY script tags pointing to src_shadow/js/index.js or production dist
176176
// This handles various relative paths and optional attributes like type="module"
177177
const distScriptRe = /<script\b[^>]*src=["'](?:(?:\.\.\/)*src_shadow\/js\/|\.\/scripts\/ai_menu\/dist\/)[^"']+\.js["'][^>]*><\/script>/gi;
178-
const before = html;
179-
html = html.replace(distScriptRe, '');
180-
const removedCount = (before.match(distScriptRe) || []).length;
178+
const removedCount = (html.match(distScriptRe) || []).length;
179+
// Loop until stable: a single replace can leave overlapping matches re-formed
180+
// (e.g. <scrip<script ...></script>t...></script>). Iterating closes that gap.
181+
let prev;
182+
do {
183+
prev = html;
184+
html = html.replace(distScriptRe, '');
185+
} while (html !== prev);
181186
if (removedCount > 0) console.log(`[vite-dev] injector removed ${removedCount} script tag(s)`);
182187

183188
// Append dev entry which Vite will transform & HMR

0 commit comments

Comments
 (0)