Skip to content

Feat: CAA validator#10267

Merged
Meldiron merged 7 commits into1.7.xfrom
feat-check-CAA-in-DNS
Aug 6, 2025
Merged

Feat: CAA validator#10267
Meldiron merged 7 commits into1.7.xfrom
feat-check-CAA-in-DNS

Conversation

@Meldiron
Copy link
Copy Markdown
Contributor

@Meldiron Meldiron commented Aug 5, 2025

What does this PR do?

Adds CAA validation before adding rule, to prevent most common certificate issue problem

Test Plan

  • Manual QA on stage

Related PRs and Issues

x

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 5, 2025

📝 Walkthrough

"""

Walkthrough

This change introduces support for validating CAA (Certification Authority Authorization) DNS records in the domain verification process. Two new environment variables are added: _APP_DNS (specifying the DNS server, defaulting to 8.8.8.8) and _APP_DOMAIN_TARGET_CAA (specifying the CAA domain target). These variables are integrated into configuration files, Docker Compose setups, and the API. The DNS validator is refactored to use the Utopia DNS client and now supports CAA record validation, including recursive parent domain checks. The domain validation logic in certificate issuance and rule verification is updated to enforce CAA checks, and corresponding tests are added and updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • vermakhushboo
    """

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3541fcb and aa837c7.

📒 Files selected for processing (4)
  • app/controllers/api/proxy.php (1 hunks)
  • app/views/install/compose.phtml (4 hunks)
  • src/Appwrite/Network/Validator/DNS.php (2 hunks)
  • src/Appwrite/Platform/Workers/Certificates.php (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/views/install/compose.phtml
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Appwrite/Platform/Workers/Certificates.php
  • app/controllers/api/proxy.php
  • src/Appwrite/Network/Validator/DNS.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: E2E Service Test (Users)
  • GitHub Check: E2E Service Test (Tokens)
  • GitHub Check: E2E Service Test (Storage)
  • GitHub Check: E2E Service Test (Projects)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (Teams)
  • GitHub Check: E2E Service Test (Realtime)
  • GitHub Check: E2E Service Test (FunctionsSchedule)
  • GitHub Check: E2E Service Test (Sites)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (Health)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Databases)
  • GitHub Check: E2E Service Test (Dev Keys)
  • GitHub Check: E2E Service Test (Site Screenshots)
  • GitHub Check: E2E General Test
  • GitHub Check: Unit Test
  • GitHub Check: scan
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-check-CAA-in-DNS

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 5, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
git 2.45.3-r0 CVE-2025-48384 HIGH
git 2.45.3-r0 CVE-2025-48385 HIGH
git-init-template 2.45.3-r0 CVE-2025-48384 HIGH
git-init-template 2.45.3-r0 CVE-2025-48385 HIGH
icu 74.2-r0 CVE-2025-5222 HIGH
icu-data-en 74.2-r0 CVE-2025-5222 HIGH
icu-dev 74.2-r0 CVE-2025-5222 HIGH
icu-libs 74.2-r0 CVE-2025-5222 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
pyc 3.12.9-r0 CVE-2024-12718 HIGH
pyc 3.12.9-r0 CVE-2025-4138 HIGH
pyc 3.12.9-r0 CVE-2025-4330 HIGH
pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3 3.12.9-r0 CVE-2024-12718 HIGH
python3 3.12.9-r0 CVE-2025-4138 HIGH
python3 3.12.9-r0 CVE-2025-4330 HIGH
python3 3.12.9-r0 CVE-2025-4517 HIGH
python3-pyc 3.12.9-r0 CVE-2024-12718 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4138 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4330 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2024-12718 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4138 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4330 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4517 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Aug 5, 2025

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@10267

commit: dade827

@Meldiron Meldiron changed the base branch from main to 1.7.x August 5, 2025 11:42
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 5, 2025

✨ Benchmark results

  • Requests per second: 994
  • Requests with 200 status code: 179,022
  • P99 latency: 0.182896438

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 994 1,028
200 179,022 185,108
P99 0.182896438 0.188628948

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

♻️ Duplicate comments (1)
app/controllers/api/proxy.php (1)

289-300: Fix hardcoded CA name in error message.

Same issue as in the certificates worker - the error message should use the environment variable value instead of hardcoding "certainly.com".

Apply this diff:

-                throw new Exception(Exception::RULE_VERIFICATION_FAILED, 'Domain verification failed because CAA records do not allow certainly.com to issue certificates.');
+                throw new Exception(Exception::RULE_VERIFICATION_FAILED, 'Domain verification failed because CAA records do not allow ' . System::getEnv('_APP_DOMAIN_TARGET_CAA', '') . ' to issue certificates.');
🧹 Nitpick comments (2)
tests/unit/Network/Validators/DNSTest.php (1)

69-69: Fix typo in comment.

Apply this diff:

-        // Valid becasue no CAA record configured
+        // Valid because no CAA record configured
src/Appwrite/Network/Validator/DNS.php (1)

24-26: Consider dependency injection for better testability

The DNS client is created directly in the validation method, making it difficult to test. Consider injecting it through the constructor.

+    private Client $dnsClient;
+    
     /**
      * @param string $target
+     * @param Client|null $dnsClient
      */
-    public function __construct(protected string $target, protected string $type = self::RECORD_CNAME)
+    public function __construct(
+        protected string $target, 
+        protected string $type = self::RECORD_CNAME,
+        ?Client $dnsClient = null
+    )
     {
+        $this->dnsClient = $dnsClient ?? new Client(System::getEnv('_APP_DNS', '8.8.8.8'));
     }

Then update the isValid method:

-        $dnsServer = System::getEnv('_APP_DNS', '8.8.8.8');
-        $dns = new Client($dnsServer);
-
         try {
-            $query = $dns->query($value, $this->type);
+            $query = $this->dnsClient->query($value, $this->type);

This would also allow reusing the same DNS client instance in recursive calls.

Also applies to: 56-58, 78-79

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0109ca2 and 2d4e99c.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • .env (1 hunks)
  • app/config/variables.php (1 hunks)
  • app/controllers/api/console.php (1 hunks)
  • app/controllers/api/proxy.php (1 hunks)
  • app/views/install/compose.phtml (4 hunks)
  • composer.json (1 hunks)
  • docker-compose.yml (4 hunks)
  • src/Appwrite/Network/Validator/DNS.php (2 hunks)
  • src/Appwrite/Platform/Workers/Certificates.php (1 hunks)
  • src/Appwrite/Utopia/Response/Model/ConsoleVariables.php (1 hunks)
  • tests/e2e/Services/Console/ConsoleConsoleClientTest.php (1 hunks)
  • tests/unit/Network/Validators/DNSTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: stnguyen90
PR: appwrite/appwrite#10119
File: app/controllers/api/account.php:1226-1232
Timestamp: 2025-07-08T01:20:14.364Z
Learning: In Appwrite, `_APP_DOMAIN` is a required environment variable that must always be set for the system to function properly.
📚 Learning: in appwrite, `_app_domain` is a required environment variable that must always be set for the system...
Learnt from: stnguyen90
PR: appwrite/appwrite#10119
File: app/controllers/api/account.php:1226-1232
Timestamp: 2025-07-08T01:20:14.364Z
Learning: In Appwrite, `_APP_DOMAIN` is a required environment variable that must always be set for the system to function properly.

Applied to files:

  • src/Appwrite/Utopia/Response/Model/ConsoleVariables.php
  • app/controllers/api/console.php
  • app/config/variables.php
  • .env
  • app/views/install/compose.phtml
  • docker-compose.yml
🧬 Code Graph Analysis (1)
tests/unit/Network/Validators/DNSTest.php (1)
src/Appwrite/Network/Validator/DNS.php (2)
  • DNS (9-130)
  • isValid (50-105)
🪛 dotenv-linter (3.3.0)
.env

[warning] 24-24: [UnorderedKey] The _APP_DNS key should go before the _APP_EDITION key


[warning] 25-25: [UnorderedKey] The _APP_DOMAIN key should go before the _APP_EDITION key


[warning] 26-26: [UnorderedKey] The _APP_CONSOLE_DOMAIN key should go before the _APP_CONSOLE_HOSTNAMES key


[warning] 27-27: [UnorderedKey] The _APP_DOMAIN_FUNCTIONS key should go before the _APP_EDITION key


[warning] 28-28: [UnorderedKey] The _APP_DOMAIN_SITES key should go before the _APP_EDITION key


[warning] 29-29: [UnorderedKey] The _APP_DOMAIN_TARGET_CNAME key should go before the _APP_EDITION key


[warning] 30-30: [UnorderedKey] The _APP_DOMAIN_TARGET_A key should go before the _APP_DOMAIN_TARGET_CNAME key


[warning] 31-31: [UnorderedKey] The _APP_DOMAIN_TARGET_AAAA key should go before the _APP_DOMAIN_TARGET_CNAME key


[warning] 32-32: [UnorderedKey] The _APP_DOMAIN_TARGET_CAA key should go before the _APP_DOMAIN_TARGET_CNAME key

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (Sites)
  • GitHub Check: E2E Service Test (Databases)
  • GitHub Check: Benchmark
🔇 Additional comments (14)
composer.json (1)

58-58: LGTM! DNS package dependency added for CAA validation.

The addition of utopia-php/dns package is appropriate for implementing CAA record validation functionality as described in the PR objectives.

tests/e2e/Services/Console/ConsoleConsoleClientTest.php (2)

27-27: Correctly updated test count for new environment variable.

The count has been appropriately increased from 13 to 14 to account for the new _APP_DOMAIN_TARGET_CAA variable.


31-31: LGTM! New CAA variable assertion added.

The assertion correctly validates that the new _APP_DOMAIN_TARGET_CAA environment variable is returned as a string type.

.env (2)

24-24: LGTM! DNS server configuration added.

The addition of _APP_DNS=8.8.8.8 provides a sensible default DNS server for CAA record validation.


32-32: LGTM! CAA domain target configured.

The _APP_DOMAIN_TARGET_CAA=digicert.com setting appropriately configures the CAA domain for certificate authority validation.

app/controllers/api/console.php (1)

74-75: LGTM! Correct CAA record formatting.

The formatting follows proper CAA DNS record syntax with flags (0), tag (issue), and quoted domain value. The comment clearly explains the purpose.

app/config/variables.php (2)

154-162: LGTM! CAA domain target variable properly configured.

The _APP_DOMAIN_TARGET_CAA variable is well-documented with a clear description. Making it optional (not required) with no default value is appropriate for CAA validation functionality.


163-171: LGTM! DNS server variable properly configured.

The _APP_DNS variable configuration is appropriate with Google's public DNS (8.8.8.8) as the default. The description clearly explains its purpose for domain validation.

src/Appwrite/Utopia/Response/Model/ConsoleVariables.php (1)

31-36: LGTM: CAA environment variable properly added.

The new _APP_DOMAIN_TARGET_CAA environment variable follows the established pattern of other domain target variables and is correctly configured with appropriate type, description, and example value.

tests/unit/Network/Validators/DNSTest.php (1)

51-76: Excellent test coverage for CAA validation.

The test method comprehensively covers various CAA record scenarios including different flag values, CA domains, and domains without CAA records. This provides good validation of the DNS validator's CAA functionality.

docker-compose.yml (4)

123-124: LGTM: Environment variables properly configured.

The new CAA and DNS environment variables are consistently added across all relevant services that handle domain validation and certificate operations.


540-541: Consistent environment variable configuration.

The variables are properly included in the certificate worker service environment.


711-712: Consistent environment variable configuration.

The variables are properly included in the migrations worker service environment.


747-748: Consistent environment variable configuration.

The variables are properly included in the maintenance task service environment.

@Meldiron Meldiron merged commit 7dd9ade into 1.7.x Aug 6, 2025
40 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 13, 2025
2 tasks
@coderabbitai coderabbitai bot mentioned this pull request Sep 11, 2025
2 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants