Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate URLs to prevent XSS #1023

Open
gtsp233 opened this issue Jan 23, 2024 · 0 comments
Open

Validate URLs to prevent XSS #1023

gtsp233 opened this issue Jan 23, 2024 · 0 comments

Comments

@gtsp233
Copy link

gtsp233 commented Jan 23, 2024

I've identified Cross-Site Scripting (XSS) vulnerabilities in '@financial-times/dotcom-ui-header' and '@financial-times-dotcom-ui-footer'

Vulnerability Details:

  • Severity: High/Critical
  • Description: There's a risk of malicious script execution when the href of the a tag is controlled by an adversary.
import { Header, Drawer } from '@financial-times/dotcom-ui-header'

<Header data={{ navbar: { items: [{ url: "javascript:alert(1)" }] } }} />

Then the malicious code alert(1) will be executed. Any React.js application using this package may be vulnerable to XSS.

Suggested Fix or Mitigation:

const NavListLeft = (props: THeaderProps) => (
<ul className="o-header__nav-list o-header__nav-list--left" data-trackable="primary-nav">
{props.data.navbar.items.map((item, index) => (
<li className="o-header__nav-item" key={`link-${index}`}>
<a
className="o-header__nav-link o-header__nav-link--primary"
href={item.url ?? undefined}
id={`o-header-link-${index}`}
{...ariaSelected(item)}
data-trackable={item.label}
>
{item.label}
</a>
{props.showMegaNav && Array.isArray(item.meganav) ? (
<MegaNav meganav={item.meganav} label={item.label} index={index} />
) : null}
</li>
))}
</ul>
)

It is best practice for a React.js components package to sanitize the href attribute before passing it to an tag. React.js and many popular libraries such as react-router-dom and Next.js also ensure the safety of href attributes. For instance, React.js issues warnings about URLs starting with javascript: and is planning to block these in future versions, as indicated in this pull request.

The same pattern can be found across these two packages. Please consider validating the href to resolve this vulnerability, Thanks!

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

No branches or pull requests

1 participant