Skip to content

Don't treat field_intro_text as HTML in benefits hub (landing_page)#1857

Open
pwolfert wants to merge 1 commit intomainfrom
pwolfert/fix-unescaped-html-string
Open

Don't treat field_intro_text as HTML in benefits hub (landing_page)#1857
pwolfert wants to merge 1 commit intomainfrom
pwolfert/fix-unescaped-html-string

Conversation

@pwolfert
Copy link
Copy Markdown
Contributor

Description

Renders Benefit Hub field_intro_text as escaped plain text with line breaks from CMS, instead of HTML via dangerouslySetInnerHTML. Also fixes inconsistent application of mobile .va-introtext styles as pointed out in the original ticket.

Instead of evaluating the contents of field_intro_text as HTML—which is dangerous because this field in particular was never sanitized on the backend—we're now treating the intro string as plain text except that we split on \r\n and join segments with <br /> in React (no dangerouslySetInnerHTML). Angle brackets and legacy “HTML-looking” content stay literal and are not parsed or executed.

Ticket

Relates to department-of-veterans-affairs/va.gov-cms#24029

Testing Steps

Go to https://va-gov-cms.ddev.site/family-and-caregiver-benefits and edit the intro text to include some script injection like <script>window.alert('all your base are belong to us!')</script>. Publish it and visit http://localhost:3999/family-and-caregiver-benefits/. On the main branch you'll be vulnerable to that script injection. On this branch, the HTML will be escaped.

QA steps

The other part of this ticket is making sure all intro text gets smaller on small screens. Shrink your window down to a mobile sized screen and see the font size change.

Screenshots

Before:

Script injection Screenshot 2026-04-24 at 1 34 17 PM

After:

No script injection Screenshot 2026-04-24 at 1 50 47 PM

@pwolfert pwolfert requested review from a team as code owners April 24, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants