← Java / Spring · Contents

JAVA-098 / Intermediate

Allowing the javascript: scheme in input such as email or image URLs

A03:2021 Injection · CWE-79 XSS

Why is this a problem?

javascript: is stored in profile links and executes when clicked.

How to fix it

java
URI u = URI.create(dto.getWebsite());
if (!Set.of("http", "https").contains(u.getScheme())) throw new IllegalArgumentException();

Further reading