From 4cafd2e07d2c775d6a19ac1bf375f5e915d7fadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 4 Aug 2025 14:28:50 +0200 Subject: [PATCH] Improve PR quality --- .env | 6 +-- app/config/variables.php | 4 +- app/controllers/api/console.php | 4 +- app/controllers/api/proxy.php | 6 +-- app/views/install/compose.phtml | 8 +++ composer.json | 2 +- composer.lock | 29 ++++------ docker-compose.yml | 8 +-- src/Appwrite/Network/Validator/DNS.php | 18 ++++++- .../Platform/Workers/Certificates.php | 7 +-- .../Response/Model/ConsoleVariables.php | 54 +++++++++---------- .../Console/ConsoleConsoleClientTest.php | 3 +- tests/unit/Network/Validators/DNSTest.php | 15 +++--- 13 files changed, 83 insertions(+), 81 deletions(-) diff --git a/.env b/.env index 7fe837ea7e..4d7c038a6b 100644 --- a/.env +++ b/.env @@ -21,6 +21,7 @@ _APP_OPTIONS_ROUTER_PROTECTION=disabled _APP_OPTIONS_FORCE_HTTPS=disabled _APP_OPTIONS_ROUTER_FORCE_HTTPS=disabled _APP_OPENSSL_KEY_V1=your-secret-key +_APP_DNS=8.8.8.8 _APP_DOMAIN=traefik _APP_CONSOLE_DOMAIN=localhost _APP_DOMAIN_FUNCTIONS=functions.localhost @@ -28,6 +29,7 @@ _APP_DOMAIN_SITES=sites.localhost _APP_DOMAIN_TARGET_CNAME=test.localhost _APP_DOMAIN_TARGET_A=127.0.0.1 _APP_DOMAIN_TARGET_AAAA=::1 +_APP_DOMAIN_TARGET_CAA=digicert.com _APP_RULES_FORMAT=md5 _APP_REDIS_HOST=redis _APP_REDIS_PORT=6379 @@ -121,6 +123,4 @@ _APP_MESSAGE_PUSH_TEST_DSN= _APP_WEBHOOK_MAX_FAILED_ATTEMPTS=10 _APP_PROJECT_REGIONS=default _APP_FUNCTIONS_CREATION_ABUSE_LIMIT=5000 -_APP_STATS_USAGE_DUAL_WRITING_DBS=database_db_main -_APP_DOMAINS_DNS=8.8.8.8 -_APP_DOMAIN_TARGET_CAA='0 issue "digicert.com"' \ No newline at end of file +_APP_STATS_USAGE_DUAL_WRITING_DBS=database_db_main \ No newline at end of file diff --git a/app/config/variables.php b/app/config/variables.php index 61a0cd563f..8fd00557b3 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -153,7 +153,7 @@ return [ ], [ 'name' => '_APP_DOMAIN_TARGET_CAA', - 'description' => 'A CAA record value that can be used to validate custom domains. Format: "0 issue \"certainly.com\""', + 'description' => 'A CAA record domain that can be used to validate custom domains. Value should be domain\'s hostname.', 'introduction' => '', 'default' => '', 'required' => false, @@ -161,7 +161,7 @@ return [ 'filter' => '' ], [ - 'name' => '_APP_DOMAINS_DNS', + 'name' => '_APP_DNS', 'description' => 'DNS server to use for domain validation. Default: 8.8.8.8', 'introduction' => '', 'default' => '8.8.8.8', diff --git a/app/controllers/api/console.php b/app/controllers/api/console.php index a564031e7c..fc9849cc17 100644 --- a/app/controllers/api/console.php +++ b/app/controllers/api/console.php @@ -71,8 +71,8 @@ App::get('/v1/console/variables') '_APP_DOMAIN_TARGET_CNAME' => System::getEnv('_APP_DOMAIN_TARGET_CNAME'), '_APP_DOMAIN_TARGET_AAAA' => System::getEnv('_APP_DOMAIN_TARGET_AAAA'), '_APP_DOMAIN_TARGET_A' => System::getEnv('_APP_DOMAIN_TARGET_A'), - '_APP_DOMAIN_TARGET_CAA' => System::getEnv('_APP_DOMAIN_TARGET_CAA'), - '_APP_DOMAINS_DNS' => System::getEnv('_APP_DOMAINS_DNS'), + // Combine CAA domain with most common flags and tag (no parameters) + '_APP_DOMAIN_TARGET_CAA' => '0 issue "' + System::getEnv('_APP_DOMAIN_TARGET_CAA') + '"', '_APP_STORAGE_LIMIT' => +System::getEnv('_APP_STORAGE_LIMIT'), '_APP_COMPUTE_SIZE_LIMIT' => +System::getEnv('_APP_COMPUTE_SIZE_LIMIT'), '_APP_USAGE_STATS' => System::getEnv('_APP_USAGE_STATS'), diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index eb7dcf625a..c2be924c40 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -256,10 +256,8 @@ App::patch('/v1/proxy/rules/:ruleId/verification') if ((new IP(IP::V6))->isValid(System::getEnv('_APP_DOMAIN_TARGET_AAAA', ''))) { $validators[] = new DNS(System::getEnv('_APP_DOMAIN_TARGET_AAAA', ''), DNS::RECORD_AAAA); } - - $caaTarget = System::getEnv('_APP_DOMAIN_TARGET_CAA', ''); - if (!empty($caaTarget)) { - $validators[] = new DNS($caaTarget, DNS::RECORD_CAA); + if (!empty(System::getEnv('_APP_DOMAIN_TARGET_CAA', ''))) { + $validators[] = new DNS(System::getEnv('_APP_DOMAIN_TARGET_CAA', ''), DNS::RECORD_CAA); } if (empty($validators)) { diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 89facfe0f1..34940e7c6e 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -95,6 +95,8 @@ $image = $this->getParam('image', ''); - _APP_DOMAIN_TARGET_CNAME - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A + - _APP_DOMAIN_TARGET_CAA + - _APP_DOMAINS_DNS - _APP_DOMAIN_FUNCTIONS - _APP_REDIS_HOST - _APP_REDIS_PORT @@ -472,6 +474,8 @@ $image = $this->getParam('image', ''); - _APP_DOMAIN_TARGET_CNAME - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A + - _APP_DOMAIN_TARGET_CAA + - _APP_DOMAINS_DNS - _APP_DOMAIN_FUNCTIONS - _APP_EMAIL_CERTIFICATES - _APP_REDIS_HOST @@ -629,6 +633,8 @@ $image = $this->getParam('image', ''); - _APP_DOMAIN_TARGET_CNAME - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A + - _APP_DOMAIN_TARGET_CAA + - _APP_DOMAINS_DNS - _APP_EMAIL_SECURITY - _APP_REDIS_HOST - _APP_REDIS_PORT @@ -660,6 +666,8 @@ $image = $this->getParam('image', ''); - _APP_DOMAIN_TARGET_CNAME - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A + - _APP_DOMAIN_TARGET_CAA + - _APP_DOMAINS_DNS - _APP_DOMAIN_FUNCTIONS - _APP_OPENSSL_KEY_V1 - _APP_REDIS_HOST diff --git a/composer.json b/composer.json index 10b8b7cc88..1f42130168 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "utopia-php/database": "0.71.*", "utopia-php/detector": "0.1.*", "utopia-php/domains": "0.8.*", - "utopia-php/dns": "dev-feat-add-CAA-to-client as 0.2.99", + "utopia-php/dns": "0.3.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", "utopia-php/fetch": "0.4.*", diff --git a/composer.lock b/composer.lock index b2c9ba0b0d..6ff2cc6fd3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d36ad770ee5e4ea6e3bb0206c2c584ff", + "content-hash": "65958cc5b58b8f32a044bb8cc33cbeef", "packages": [ { "name": "adhocore/jwt", @@ -3598,16 +3598,16 @@ }, { "name": "utopia-php/dns", - "version": "dev-feat-add-CAA-to-client", + "version": "0.3.0", "source": { "type": "git", "url": "https://github.com/utopia-php/dns.git", - "reference": "a7d45e4c5dfc7020c0467de9587ccd7e15488206" + "reference": "8fd4161bc3a8021a670c1101b40f6b09a97f1a54" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/dns/zipball/a7d45e4c5dfc7020c0467de9587ccd7e15488206", - "reference": "a7d45e4c5dfc7020c0467de9587ccd7e15488206", + "url": "https://api.github.com/repos/utopia-php/dns/zipball/8fd4161bc3a8021a670c1101b40f6b09a97f1a54", + "reference": "8fd4161bc3a8021a670c1101b40f6b09a97f1a54", "shasum": "" }, "require": { @@ -3648,9 +3648,9 @@ ], "support": { "issues": "https://github.com/utopia-php/dns/issues", - "source": "https://github.com/utopia-php/dns/tree/feat-add-CAA-to-client" + "source": "https://github.com/utopia-php/dns/tree/0.3.0" }, - "time": "2025-08-03T18:46:13+00:00" + "time": "2025-08-04T11:05:53+00:00" }, { "name": "utopia-php/domains", @@ -8317,18 +8317,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/dns", - "version": "dev-feat-add-CAA-to-client", - "alias": "0.2.99", - "alias_normalized": "0.2.99.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/dns": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -8352,5 +8343,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/docker-compose.yml b/docker-compose.yml index 830e0905fa..0e299c8a2c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -121,7 +121,7 @@ services: - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A - _APP_DOMAIN_TARGET_CAA - - _APP_DOMAINS_DNS + - _APP_DNS - _APP_DOMAIN_FUNCTIONS - _APP_REDIS_HOST - _APP_REDIS_PORT @@ -538,7 +538,7 @@ services: - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A - _APP_DOMAIN_TARGET_CAA - - _APP_DOMAINS_DNS + - _APP_DNS - _APP_DOMAIN_FUNCTIONS - _APP_EMAIL_CERTIFICATES - _APP_REDIS_HOST @@ -709,7 +709,7 @@ services: - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A - _APP_DOMAIN_TARGET_CAA - - _APP_DOMAINS_DNS + - _APP_DNS - _APP_EMAIL_SECURITY - _APP_REDIS_HOST - _APP_REDIS_PORT @@ -745,7 +745,7 @@ services: - _APP_DOMAIN_TARGET_AAAA - _APP_DOMAIN_TARGET_A - _APP_DOMAIN_TARGET_CAA - - _APP_DOMAINS_DNS + - _APP_DNS - _APP_DOMAIN_FUNCTIONS - _APP_OPENSSL_KEY_V1 - _APP_REDIS_HOST diff --git a/src/Appwrite/Network/Validator/DNS.php b/src/Appwrite/Network/Validator/DNS.php index 7557a0d04b..b28ef2f800 100644 --- a/src/Appwrite/Network/Validator/DNS.php +++ b/src/Appwrite/Network/Validator/DNS.php @@ -11,7 +11,7 @@ class DNS extends Validator public const RECORD_A = 'a'; public const RECORD_AAAA = 'aaaa'; public const RECORD_CNAME = 'cname'; - public const RECORD_CAA = 'caa'; + public const RECORD_CAA = 'caa'; // Only provide domain as $target for CAA validation /** * @var mixed @@ -53,7 +53,7 @@ class DNS extends Validator return false; } - $dnsServer = System::getEnv('_APP_DOMAINS_DNS', '8.8.8.8'); + $dnsServer = System::getEnv('_APP_DNS', '8.8.8.8'); $dns = new Client($dnsServer); try { @@ -69,6 +69,20 @@ class DNS extends Validator } foreach ($query as $record) { + // CAA validation only needs to ensure domain + if ($this->type === self::RECORD_CAA) { + // Original: 255 issuewild "certainly.com;validationmethods=tls-alpn-01;retrytimeout=3600" + // Extracted: certainly.com + $rdata = $record->getRdata(); + $rdata = \explode(' ', $rdata, 3)[2] ?? ''; + $rdata = \trim('"'); + $rdata = \explode(';', $rdata, 2)[0] ?? ''; + + if ($rdata === $this->target) { + return true; + } + } + if ($record->getRdata() === $this->target) { return true; } diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index dd927aae84..fc2878a1d0 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -313,11 +313,8 @@ class Certificates extends Action if ((new IP(IP::V6))->isValid(System::getEnv('_APP_DOMAIN_TARGET_AAAA', ''))) { $validators[] = new DNS(System::getEnv('_APP_DOMAIN_TARGET_AAAA', ''), DNS::RECORD_AAAA); } - - // Add CAA validation if configured - $caaTarget = System::getEnv('_APP_DOMAIN_TARGET_CAA', ''); - if (!empty($caaTarget)) { - $validators[] = new DNS($caaTarget, DNS::RECORD_CAA); + if (!empty(System::getEnv('_APP_DOMAIN_TARGET_CAA', ''))) { + $validators[] = new DNS(System::getEnv('_APP_DOMAIN_TARGET_CAA', ''), DNS::RECORD_CAA); } // Validate if domain target is properly configured diff --git a/src/Appwrite/Utopia/Response/Model/ConsoleVariables.php b/src/Appwrite/Utopia/Response/Model/ConsoleVariables.php index 21141254ab..b81502f0a1 100644 --- a/src/Appwrite/Utopia/Response/Model/ConsoleVariables.php +++ b/src/Appwrite/Utopia/Response/Model/ConsoleVariables.php @@ -10,36 +10,30 @@ class ConsoleVariables extends Model public function __construct() { $this - ->addRule('_APP_DOMAIN_TARGET_CNAME', [ - 'type' => self::TYPE_STRING, - 'description' => 'CNAME target for your Appwrite custom domains.', - 'default' => '', - 'example' => 'appwrite.io', - ]) - ->addRule('_APP_DOMAIN_TARGET_A', [ - 'type' => self::TYPE_STRING, - 'description' => 'A target for your Appwrite custom domains.', - 'default' => '', - 'example' => '127.0.0.1', - ]) - ->addRule('_APP_DOMAIN_TARGET_AAAA', [ - 'type' => self::TYPE_STRING, - 'description' => 'AAAA target for your Appwrite custom domains.', - 'default' => '', - 'example' => '::1', - ]) - ->addRule('_APP_DOMAIN_TARGET_CAA', [ - 'type' => self::TYPE_STRING, - 'description' => 'CAA target for your Appwrite custom domains.', - 'default' => '', - 'example' => '0 issue "certainly.com"', - ]) - ->addRule('_APP_DOMAINS_DNS', [ - 'type' => self::TYPE_STRING, - 'description' => 'DNS server to use for domain validation.', - 'default' => '8.8.8.8', - 'example' => '8.8.8.8', - ]) + ->addRule('_APP_DOMAIN_TARGET_CNAME', [ + 'type' => self::TYPE_STRING, + 'description' => 'CNAME target for your Appwrite custom domains.', + 'default' => '', + 'example' => 'appwrite.io', + ]) + ->addRule('_APP_DOMAIN_TARGET_A', [ + 'type' => self::TYPE_STRING, + 'description' => 'A target for your Appwrite custom domains.', + 'default' => '', + 'example' => '127.0.0.1', + ]) + ->addRule('_APP_DOMAIN_TARGET_AAAA', [ + 'type' => self::TYPE_STRING, + 'description' => 'AAAA target for your Appwrite custom domains.', + 'default' => '', + 'example' => '::1', + ]) + ->addRule('_APP_DOMAIN_TARGET_CAA', [ + 'type' => self::TYPE_STRING, + 'description' => 'CAA target for your Appwrite custom domains.', + 'default' => '', + 'example' => 'digicert.com', + ]) ->addRule('_APP_STORAGE_LIMIT', [ 'type' => self::TYPE_INTEGER, 'description' => 'Maximum file size allowed for file upload in bytes.', diff --git a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php index bfad5b480b..340cabc8c0 100644 --- a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php +++ b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php @@ -24,7 +24,7 @@ class ConsoleConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(15, $response['body']); + $this->assertCount(14, $response['body']); $this->assertIsString($response['body']['_APP_DOMAIN_TARGET_CNAME']); $this->assertIsString($response['body']['_APP_DOMAIN_TARGET_A']); $this->assertIsString($response['body']['_APP_DOMAIN_TARGET_AAAA']); @@ -38,7 +38,6 @@ class ConsoleConsoleClientTest extends Scope $this->assertIsString($response['body']['_APP_DOMAIN_FUNCTIONS']); $this->assertIsString($response['body']['_APP_OPTIONS_FORCE_HTTPS']); $this->assertIsString($response['body']['_APP_DOMAINS_NAMESERVERS']); - $this->assertIsString($response['body']['_APP_DOMAINS_DNS']); // When adding new keys, dont forget to update count a few lines above } } diff --git a/tests/unit/Network/Validators/DNSTest.php b/tests/unit/Network/Validators/DNSTest.php index 64293258a4..42417cce05 100644 --- a/tests/unit/Network/Validators/DNSTest.php +++ b/tests/unit/Network/Validators/DNSTest.php @@ -50,18 +50,19 @@ class DNSTest extends TestCase public function testCAA(): void { - $validator = new DNS('0 issue "digicert.com"', DNS::RECORD_CAA); + $validator = new DNS('digicert.com', DNS::RECORD_CAA); + $this->assertEquals($validator->isValid('github.com'), true); $this->assertEquals($validator->isValid(''), false); $this->assertEquals($validator->isValid(null), false); $this->assertEquals($validator->isValid(false), false); - - $result = $validator->isValid('github.com'); - $this->assertEquals($result, true); - $this->assertEquals($validator->isValid('test1.appwrite.org'), false); - $validator2 = new DNS('0 issue "letsencrypt.org"', DNS::RECORD_CAA); - $this->assertEquals($validator2->isValid('test2.appwrite.org'), false); + $validator = new DNS('0 issue "digicert.com"', DNS::RECORD_CAA); + + $this->assertEquals($validator->isValid('github.com'), false); + + $validator = new DNS('letsencrypt.org', DNS::RECORD_CAA); + $this->assertEquals($validator->isValid('test2.appwrite.org'), false); } }