Skip to content

Commit a6e636f

Browse files
author
aazad
committed
Fix stored XSS in user profile description
strip_tags() allows <a> tags but does not remove HTML attributes, allowing event handlers like onmouseover to pass through. The description is rendered unescaped via {!! !!} in linkinfo.blade.php, enabling stored XSS. Add regex filters to strip all on* event handler attributes (both quoted and unquoted values) from the sanitized description before saving to the database.
1 parent 2dfa544 commit a6e636f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

app/Http/Controllers/UserController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ public function editPage(Request $request)
609609
$profilePhoto = $request->file('image');
610610
$pageName = $request->littlelink_name;
611611
$pageDescription = strip_tags($request->pageDescription, '<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
612+
$pageDescription = preg_replace('/\s+on\w+\s*=\s*(["\']).*?\1/i', '', $pageDescription);
613+
$pageDescription = preg_replace('/\s+on\w+\s*=\s*[^\s>]*/i', '', $pageDescription);
612614
$pageDescription = preg_replace("/<a([^>]*)>/i", "<a $1 rel=\"noopener noreferrer nofollow\">", $pageDescription);
613615
$pageDescription = strip_tags_except_allowed_protocols($pageDescription);
614616
$name = $request->name;

0 commit comments

Comments
 (0)