Skip to content

Commit

Permalink
Impoved validation for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianPrieber committed Feb 5, 2024
1 parent cc6a119 commit 9447d21
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,12 +1169,32 @@ public function importData(Request $request)

// Loop through each link in $userData and create a new link for the user
foreach ($userData['links'] as $linkData) {

$validatedData = Validator::make($linkData, [
'link' => 'nullable|url',
]);

if ($validatedData->fails()) {
throw new \Exception('Invalid link');
}

$newLink = new Link();

// Copy over the link data from $linkData to $newLink
$newLink->button_id = $linkData['button_id'];
$newLink->link = $linkData['link'];
$newLink->title = $linkData['title'];

// Sanitize the title
if ($linkData['button_id'] == 93) {
$sanitizedText = strip_tags($linkData['title'], '<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
$sanitizedText = preg_replace("/<a([^>]*)>/i", "<a $1 rel=\"noopener noreferrer nofollow\">", $sanitizedText);
$sanitizedText = strip_tags_except_allowed_protocols($sanitizedText);

$newLink->title = $sanitizedText;
} else {
$newLink->title = $linkData['title'];
}

$newLink->order = $linkData['order'];
$newLink->click_number = 0;
$newLink->up_link = $linkData['up_link'];
Expand Down

0 comments on commit 9447d21

Please sign in to comment.