Skip to content

Commit 9038958

Browse files
committed
SSR: Updated allow list handling & covered webhook usage
- Covered webhook SSR allow list useage via test. - Updated allow list handling to use trailing slash, or hash, or end of line as late anchor for better handling for hosts (prevent .co.uk passing for .co domain host)
1 parent c324ad9 commit 9038958

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

app/Util/SsrUrlValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function allowed(string $url): bool
4141

4242
protected function urlMatchesPattern($url, $pattern): bool
4343
{
44-
$pattern = trim($pattern);
44+
$pattern = rtrim(trim($pattern), '/');
4545
$url = trim($url);
4646

4747
if (empty($pattern) || empty($url)) {
@@ -51,7 +51,7 @@ protected function urlMatchesPattern($url, $pattern): bool
5151
$quoted = preg_quote($pattern, '/');
5252
$regexPattern = str_replace('\*', '.*', $quoted);
5353

54-
return preg_match('/^' . $regexPattern . '.*$/i', $url);
54+
return preg_match('/^' . $regexPattern . '($|\/.*$|#.*$)/i', $url);
5555
}
5656

5757
/**

tests/Actions/WebhookCallTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ public function test_webhook_call_exception_is_caught_and_logged()
101101
$this->assertNotNull($webhook->last_errored_at);
102102
}
103103

104+
public function test_webhook_uses_ssr_hosts_option_if_set()
105+
{
106+
config()->set('app.ssr_hosts', 'https://*.example.com');
107+
$http = Http::fake();
108+
109+
$webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.co.uk'], ['all']);
110+
$this->runEvent(ActivityType::ROLE_CREATE);
111+
$http->assertNothingSent();
112+
113+
$webhook->refresh();
114+
$this->assertEquals('The URL does not match the configured allowed SSR hosts', $webhook->last_error);
115+
$this->assertNotNull($webhook->last_errored_at);
116+
}
117+
104118
public function test_webhook_call_data_format()
105119
{
106120
Http::fake([

tests/Unit/SsrUrlValidatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function test_allowed()
2525
['config' => 'https://*.example.com', 'url' => 'https://test.example.com', 'result' => true],
2626
['config' => '*//example.com', 'url' => 'https://example.com', 'result' => true],
2727
['config' => '*//example.com', 'url' => 'http://example.com', 'result' => true],
28+
['config' => '*//example.co', 'url' => 'http://example.co.uk', 'result' => false],
29+
['config' => '*//example.co/bookstack', 'url' => 'https://example.co/bookstack/a/path', 'result' => true],
30+
['config' => '*//example.co*', 'url' => 'https://example.co.uk/bookstack/a/path', 'result' => true],
2831
['config' => 'https://example.com', 'url' => 'https://example.com/a/b/c?test=cat', 'result' => true],
2932
['config' => 'https://example.com', 'url' => 'https://example.co.uk', 'result' => false],
3033

0 commit comments

Comments
 (0)