Skip to content

Commit c7e2b48

Browse files
committed
Attachments: Aligned ZipExportAttachment link validation
With controller routes. Don't consider this as a security issue, since the filtered URLs by that validation are very likely to be blocked by browser security or CSP, and there's a level of assumed privilege to the users that are able to create such attachments links already. Closes #6093
1 parent 4e3fa48 commit c7e2b48

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

app/Exports/ZipExports/Models/ZipExportAttachment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static function validate(ZipValidationHelper $context, array $data): arra
4545
$rules = [
4646
'id' => ['nullable', 'int', $context->uniqueIdRule('attachment')],
4747
'name' => ['required', 'string', 'min:1'],
48-
'link' => ['required_without:file', 'nullable', 'string'],
48+
'link' => ['required_without:file', 'nullable', 'string', 'safe_url'],
4949
'file' => ['required_without:link', 'nullable', 'string', $context->fileReferenceRule()],
5050
];
5151

tests/Exports/ZipExportValidatorTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,29 @@ public function test_image_files_need_to_be_a_valid_detected_image_file()
9090

9191
$this->assertEquals('The file needs to reference a file of type image/png,image/jpeg,image/gif,image/webp, found text/plain.', $results['page.images.0.file']);
9292
}
93+
94+
public function test_page_link_attachments_cant_be_data_or_js()
95+
{
96+
$validateResultCountByLink = [
97+
'data:text/html,<p>hi</p>' => 1,
98+
'javascript:alert(\'hi\')' => 1,
99+
'mailto:email@example.com' => 0,
100+
];
101+
102+
foreach ($validateResultCountByLink as $link => $count) {
103+
$validator = $this->getValidatorForData([
104+
'page' => [
105+
'id' => 4,
106+
'name' => 'My page',
107+
'markdown' => 'hello',
108+
'attachments' => [
109+
['id' => 4, 'name' => 'Attachment A', 'link' => $link],
110+
],
111+
]
112+
]);
113+
114+
$results = $validator->validate();
115+
$this->assertCount($count, $results);
116+
}
117+
}
93118
}

0 commit comments

Comments
 (0)