← PHP / Laravel · Contents

PHP-030 / Intermediate

URL input in Blade attributes (javascript: scheme)

A03:2021 Injection · CWE-79 XSS

Why is this a problem?

The {{ }} escaping mechanism does not block the javascript: scheme.

How to fix it

php
// Validate before saving
$request->validate(['website' => ['nullable', 'url:http,https']]);
blade
<a href="{{ $safeUrl }}" rel="noopener noreferrer">Homepage</a>

Further reading