77 */
88
99import type { createRequestHandler } from '@angular/ssr' ;
10- import type { createNodeRequestHandler } from '@angular/ssr/node' with { 'resolution-mode' : 'import' } ;
10+ import type { createNodeRequestHandler } from '@angular/ssr/node' with {
11+ 'resolution-mode' : 'import' ,
12+ } ;
1113
1214export function isSsrNodeRequestHandler (
1315 value : unknown ,
@@ -20,26 +22,53 @@ export function isSsrRequestHandler(
2022 return typeof value === 'function' && '__ng_request_handler__' in value ;
2123}
2224
25+ /**
26+ * A mapping of the characters which have to be escaped to be interpolated into HTML,
27+ * to their entity equivalents.
28+ */
29+ const HTML_ESCAPE_CHARACTER_MAP : Record < string , string > = {
30+ '&' : '&' ,
31+ '<' : '<' ,
32+ '>' : '>' ,
33+ '"' : '"' ,
34+ "'" : ''' ,
35+ } ;
36+
37+ /**
38+ * Escapes the characters of a value which is interpolated into HTML text or into a quoted
39+ * attribute value.
40+ *
41+ * @param text - The value to escape.
42+ * @returns The escaped value.
43+ */
44+ function escapeHtml ( text : string ) : string {
45+ return text . replace ( / [ & < > " ' ] / g, ( character ) => HTML_ESCAPE_CHARACTER_MAP [ character ] ) ;
46+ }
47+
2348/**
2449 * Generates a static HTML page with a meta refresh tag to redirect the user to a specified URL.
2550 *
2651 * This function creates a simple HTML page that performs a redirect using a meta tag.
2752 * It includes a fallback link in case the meta-refresh doesn't work.
2853 *
54+ * The provided URL is HTML-escaped before being interpolated.
55+ *
2956 * @param url - The URL to which the page should redirect.
3057 * @returns The HTML content of the static redirect page.
3158 */
3259export function generateRedirectStaticPage ( url : string ) : string {
60+ const escapedUrl = escapeHtml ( url ) ;
61+
3362 return `
3463<!DOCTYPE html>
3564<html>
3665 <head>
3766 <meta charset="utf-8">
3867 <title>Redirecting</title>
39- <meta http-equiv="refresh" content="0; url=${ url } ">
68+ <meta http-equiv="refresh" content="0; url=${ escapedUrl } ">
4069 </head>
4170 <body>
42- <pre>Redirecting to <a href="${ url } ">${ url } </a></pre>
71+ <pre>Redirecting to <a href="${ escapedUrl } ">${ escapedUrl } </a></pre>
4372 </body>
4473</html>
4574` . trim ( ) ;
0 commit comments