@magneticjs/server 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/jsx-runtime.ts +13 -4
package/package.json
CHANGED
package/src/jsx-runtime.ts
CHANGED
|
@@ -26,9 +26,11 @@ type Component = (props: any) => DomNode;
|
|
|
26
26
|
* Client-side navigation link. Renders an <a> that magnetic.js intercepts
|
|
27
27
|
* to do pushState + send navigate action (no full page reload).
|
|
28
28
|
*/
|
|
29
|
-
export function Link(props: { href: string; children?: Child | Child[]; class?: string; [k: string]: unknown }): DomNode {
|
|
30
|
-
const { href, children, ...rest } = props;
|
|
31
|
-
|
|
29
|
+
export function Link(props: { href: string; prefetch?: boolean; children?: Child | Child[]; class?: string; [k: string]: unknown }): DomNode {
|
|
30
|
+
const { href, prefetch, children, ...rest } = props;
|
|
31
|
+
const extra: Record<string, unknown> = { ...rest, href, onClick: `navigate:${href}` };
|
|
32
|
+
if (prefetch) extra['data-prefetch'] = href;
|
|
33
|
+
return jsx('a', { ...extra, children }, undefined);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -44,6 +46,9 @@ export function Head({ children }: { children?: Child | Child[] }): DomNode {
|
|
|
44
46
|
return { tag: 'magnetic:head', children: flat };
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
// URI attributes to sanitize against javascript: injection
|
|
50
|
+
const URI_ATTRS = new Set(['href', 'src', 'action', 'formaction', 'xlink:href']);
|
|
51
|
+
|
|
47
52
|
// Event prop prefix → event name mapping
|
|
48
53
|
const EVENT_MAP: Record<string, string> = {
|
|
49
54
|
onClick: 'click',
|
|
@@ -109,7 +114,11 @@ export function jsx(tag: string | Component, props: Props, key?: string | number
|
|
|
109
114
|
continue;
|
|
110
115
|
}
|
|
111
116
|
|
|
112
|
-
|
|
117
|
+
// Sanitize URI attributes — defense in depth against javascript: injection
|
|
118
|
+
const sv = String(v);
|
|
119
|
+
if (URI_ATTRS.has(k) && /^\s*javascript\s*:/i.test(sv)) continue;
|
|
120
|
+
|
|
121
|
+
attrs[k] = sv;
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
if (Object.keys(attrs).length) node.attrs = attrs;
|