mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Merge branch '1.8.x' of https://github.com/appwrite/appwrite into migration-cleanup
This commit is contained in:
commit
54ba59da64
2 changed files with 19 additions and 1 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Appwrite\Network;
|
||||
|
||||
use Utopia\Validator\Hostname;
|
||||
|
||||
/**
|
||||
* Generate CORS response headers for an incoming request.
|
||||
*
|
||||
|
|
@ -76,7 +78,8 @@ final class Cors
|
|||
}
|
||||
|
||||
// Match only by host
|
||||
if (!\in_array($host, $this->allowedHosts, true)) {
|
||||
$validator = new Hostname($this->allowedHosts);
|
||||
if (!$validator->isValid($host)) {
|
||||
return $headers;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,21 @@ final class CorsTest extends TestCase
|
|||
$this->assertSame('https://foo.com', $result[Cors::HEADER_ALLOW_ORIGIN]);
|
||||
}
|
||||
|
||||
public function testSubdomainWildcardAllowsAnySubdomain(): void
|
||||
{
|
||||
$cors = new Cors(
|
||||
allowedHosts: ['*.example.com'],
|
||||
allowedMethods: ['GET'],
|
||||
allowedHeaders: ['X-Test'],
|
||||
exposedHeaders: [],
|
||||
allowCredentials: false
|
||||
);
|
||||
|
||||
$result = $cors->headers('https://foo.example.com');
|
||||
|
||||
$this->assertSame('https://foo.example.com', $result[Cors::HEADER_ALLOW_ORIGIN]);
|
||||
}
|
||||
|
||||
public function testEmptyOriginReturnsStaticHeadersOnly(): void
|
||||
{
|
||||
$cors = new Cors(
|
||||
|
|
|
|||
Loading…
Reference in a new issue