@@ -170,7 +170,12 @@ <h2>Examples</h2>
170170 if ( start === - 1 ) break ;
171171 const marker = text . indexOf ( ';base64,' , start ) ;
172172 const subtype = marker === - 1 ? '' : text . slice ( start + 11 , marker ) ;
173- if ( marker === - 1 || subtype . length > 20 || ! / ^ [ a - z . + - ] + $ / . test ( subtype ) ) {
173+ // `svg+xml` is excluded on purpose: an SVG is markup, and while a browser
174+ // does not run scripts in one loaded through <img src>, the pipeline never
175+ // emits SVG pictures anyway (crops are PNG) — so a data:image/svg+xml run
176+ // in the output is not ours to render.
177+ if ( marker === - 1 || subtype . length > 20 || ! / ^ [ a - z . + - ] + $ / . test ( subtype )
178+ || subtype === 'svg+xml' ) {
174179 from = start + 11 ;
175180 continue ;
176181 }
@@ -263,18 +268,28 @@ <h2>Examples</h2>
263268 return ;
264269 }
265270 // Stream the body into the panel as it arrives (Markdown streams page by page).
271+ // The text is accumulated in a variable and mirrored into the panel, never
272+ // read back out of it: re-reading a multi-megabyte textContent per chunk is
273+ // quadratic, and the gallery must render from the response we received
274+ // rather than from DOM text (CodeQL js/xss-through-dom).
266275 out . textContent = '' ;
276+ let body = '' ;
267277 const reader = response . body . getReader ( ) ;
268278 const decoder = new TextDecoder ( ) ;
269279 for ( ; ; ) {
270280 const { done, value } = await reader . read ( ) ;
271281 if ( done ) break ;
272- out . textContent += decoder . decode ( value , { stream : true } ) ;
282+ const chunk = decoder . decode ( value , { stream : true } ) ;
283+ body += chunk ;
284+ out . textContent += chunk ;
273285 }
274286 if ( to === 'json' || to === 'chunks' ) {
275- try { out . textContent = JSON . stringify ( JSON . parse ( out . textContent ) , null , 2 ) ; } catch { }
287+ try {
288+ body = JSON . stringify ( JSON . parse ( body ) , null , 2 ) ;
289+ out . textContent = body ;
290+ } catch { }
276291 }
277- try { renderImages ( out . textContent , to ) ; } catch ( e ) { console . error ( 'gallery:' , e ) ; }
292+ try { renderImages ( body , to ) ; } catch ( e ) { console . error ( 'gallery:' , e ) ; }
278293 } catch ( e ) {
279294 out . classList . add ( 'err' ) ;
280295 out . textContent = String ( e ) ;
0 commit comments