fix: reject protocol-relative deep_link
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
@@ -89,7 +89,11 @@ class ClientApiTest extends TestCase
|
||||
$this->putJson('/api/events', ['events' => [$bad]], $this->auth())
|
||||
->assertStatus(422)->assertJsonValidationErrors(['events.0.payload.deep_link']);
|
||||
|
||||
$ok1 = $this->item(['payload' => ['title' => 'x', 'deep_link' => '/people/42']]);
|
||||
$protocolRelative = $this->item(['payload' => ['title' => 'x', 'deep_link' => '//evil.com/x']]);
|
||||
$this->putJson('/api/events', ['events' => [$protocolRelative]], $this->auth())
|
||||
->assertStatus(422)->assertJsonValidationErrors(['events.0.payload.deep_link']);
|
||||
|
||||
$ok1 = $this->item(['payload' => ['title' => 'x', 'deep_link' => '/people/42?x=1']]);
|
||||
$this->putJson('/api/events', ['events' => [$ok1]], $this->auth())->assertOk();
|
||||
|
||||
$ok2 = $this->item(['topic' => 'birthday:2027', 'payload' => ['title' => 'x', 'deep_link' => 'https://docs.example/x']]);
|
||||
|
||||
@@ -100,10 +100,18 @@ class InboxPageTest extends TestCase
|
||||
'after_due' => AfterDue::Keep, 'payload' => ['title' => 'Опасное событие', 'deep_link' => 'javascript:alert(1)'],
|
||||
'state' => EventState::Today, 'quiet_until' => CarbonImmutable::parse('2000-01-01Z'),
|
||||
]);
|
||||
Event::create([
|
||||
'source_id' => $source->id, 'user_id' => $user->id, 'source_ref' => 'r', 'topic' => 'b',
|
||||
'due_mode' => DueMode::Local, 'due_date' => '2026-09-04', 'due_time' => '24:00:00', 'fire_on' => '2026-09-04',
|
||||
'after_due' => AfterDue::Keep, 'payload' => ['title' => 'Протокольная ссылка', 'deep_link' => '//evil.com/x'],
|
||||
'state' => EventState::Today, 'quiet_until' => CarbonImmutable::parse('2000-01-01Z'),
|
||||
]);
|
||||
|
||||
$html = $this->get('/', ['X-Remote-User' => 'nikita'])->assertOk()->getContent();
|
||||
|
||||
$this->assertStringNotContainsString('href="javascript:', $html);
|
||||
$this->assertStringNotContainsString('href="//evil', $html);
|
||||
$this->assertStringContainsString('Опасное событие', $html);
|
||||
$this->assertStringContainsString('Протокольная ссылка', $html);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user