Skip to content

Escape interpolated paths in generated virtual modules #149

Description

@uhyo

Problem

The virtual:funstack/entries, client-init, and build-entry loaders in packages/static/src/plugin/index.ts splice resolved paths into generated code as raw string literals:

return `export { default } from "${resolvedEntriesModule}";`;
// ...
`import Root from "${root}";`,
`import "${resolvedClientInitEntry}";`,

normalizePath converts backslashes to forward slashes, but a path containing a " (or other characters needing escaping in a JS string literal) still produces a syntax error — or in the worst case, injected code — in the generated module. The glob pattern in the fsRoutes branch is already correctly embedded with JSON.stringify; the path interpolations should be too.

Suggested fix

Wrap every interpolated path with JSON.stringify(...) when emitting the import/export statements.

Found during a framework audit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions