Skip to content

Commit 4639d0f

Browse files
committed
update for RFC compliant
1 parent 4f3e011 commit 4639d0f

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/DNS/Server.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ protected function encodeSrv(string $domain, int $ttl, int $priority, int $weigh
429429

430430
protected function encodeCAA(array|string $rdata, int $ttl): string
431431
{
432-
// Accept either array or string for rdata
433-
// If string, parse as 'tag value' (e.g. 'issue "letsencrypt.org"')
434432
$flags = 0;
435433
$tag = '';
436434
$value = '';
@@ -439,16 +437,23 @@ protected function encodeCAA(array|string $rdata, int $ttl): string
439437
$tag = (string)($rdata['tag'] ?? 'issue');
440438
$value = (string)($rdata['value'] ?? '');
441439
} elseif (is_string($rdata)) {
442-
// Try to parse: 'issue "letsencrypt.org"' or 'issuewild "example.com"'
443-
if (preg_match('/^(issue|issuewild|iodef)\s+"([^"]+)"$/', $rdata, $m)) {
444-
$tag = $m[1];
445-
$value = $m[2];
440+
// Parse: 'flags tag "value"' or 'tag "value"' or 'flags tag value' or 'tag value'
441+
if (preg_match('/^(?:(\d+)\s+)?([a-zA-Z0-9_-]+)\s+"([^"]+)"$/', $rdata, $m)) {
442+
$flags = isset($m[1]) ? (int)$m[1] : 0;
443+
$tag = $m[2];
444+
$value = $m[3];
445+
} elseif (preg_match('/^(?:(\d+)\s+)?([a-zA-Z0-9_-]+)\s+(.+)$/', $rdata, $m)) {
446+
$flags = isset($m[1]) ? (int)$m[1] : 0;
447+
$tag = $m[2];
448+
$value = $m[3];
446449
} else {
447-
// fallback: treat all as value
450+
// fallback: treat all as issue value
448451
$tag = 'issue';
449452
$value = $rdata;
450453
}
451454
}
455+
// Validate flags (must be 0-255)
456+
$flags = max(0, min(255, $flags));
452457
$tagLen = strlen($tag);
453458
$valueLen = strlen($value);
454459
$rdataBin = chr($flags) . chr($tagLen) . $tag . $value;

0 commit comments

Comments
 (0)