Skip to content

Commit 21644b2

Browse files
committed
fix: encode author names in onerror fallback to prevent XSS
The onerror handlers on testimonial avatar images interpolate t.author directly into a JavaScript string literal. Because browsers decode HTML entities before executing event handler attributes, a single quote in an author name (e.g. O'Malley) breaks out of the JS string and enables arbitrary script execution. Apply encodeURIComponent() at build time so special characters are percent-encoded, which both prevents the string breakout and properly URL-encodes the ui-avatars.com name parameter. Affects index.astro (2 instances) and shoutouts.astro (1 instance). Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent 3c43195 commit 21644b2

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/pages/index.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const featuredPress = pressArticles.slice(0, 4);
125125
alt={t.author}
126126
class="testimonial-avatar"
127127
loading="lazy"
128-
onerror={`this.src='https://ui-avatars.com/api/?name=${t.author}&background=FF4D4D&color=fff&size=88'`}
128+
onerror={`this.src='https://ui-avatars.com/api/?name=${encodeURIComponent(t.author)}&background=FF4D4D&color=fff&size=88'`}
129129
/>
130130
<div class="testimonial-content">
131131
<p class="testimonial-quote">"{t.quote}"</p>
@@ -142,7 +142,7 @@ const featuredPress = pressArticles.slice(0, 4);
142142
alt={t.author}
143143
class="testimonial-avatar"
144144
loading="lazy"
145-
onerror={`this.src='https://ui-avatars.com/api/?name=${t.author}&background=FF4D4D&color=fff&size=88'`}
145+
onerror={`this.src='https://ui-avatars.com/api/?name=${encodeURIComponent(t.author)}&background=FF4D4D&color=fff&size=88'`}
146146
/>
147147
<div class="testimonial-content">
148148
<p class="testimonial-quote">"{t.quote}"</p>

src/pages/shoutouts.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const allTestimonials = [...testimonials, ...extraTestimonials];
2828
alt={t.author}
2929
class="shoutout-avatar"
3030
loading="lazy"
31-
onerror={`this.src='https://ui-avatars.com/api/?name=${t.author}&background=FF4D4D&color=fff&size=96'`}
31+
onerror={`this.src='https://ui-avatars.com/api/?name=${encodeURIComponent(t.author)}&background=FF4D4D&color=fff&size=96'`}
3232
/>
3333
<div class="shoutout-content">
3434
<p class="shoutout-quote">"{t.quote}"</p>

0 commit comments

Comments
 (0)