From 26f1ba79901f783785b4757324bc9a8cc027bd52 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 17 Feb 2026 10:37:45 +0000 Subject: [PATCH 1/2] Update utopia-php/span to 1.1.5 and set span level to warn on FORMERR responses Co-Authored-By: Claude Opus 4.6 --- composer.lock | 12 ++++++------ src/DNS/Server.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 74f4699..f49f7be 100644 --- a/composer.lock +++ b/composer.lock @@ -2036,16 +2036,16 @@ }, { "name": "utopia-php/span", - "version": "1.1.4", + "version": "1.1.5", "source": { "type": "git", "url": "https://github.com/utopia-php/span.git", - "reference": "49d04aa588a2cdbbc9381ee7a1c129469e0f905c" + "reference": "028406940ca92bdc88099f0b1a123a3b2cbdd4e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/span/zipball/49d04aa588a2cdbbc9381ee7a1c129469e0f905c", - "reference": "49d04aa588a2cdbbc9381ee7a1c129469e0f905c", + "url": "https://api.github.com/repos/utopia-php/span/zipball/028406940ca92bdc88099f0b1a123a3b2cbdd4e5", + "reference": "028406940ca92bdc88099f0b1a123a3b2cbdd4e5", "shasum": "" }, "require": { @@ -2074,9 +2074,9 @@ "description": "Simple span tracing library for PHP with coroutine support", "support": { "issues": "https://github.com/utopia-php/span/issues", - "source": "https://github.com/utopia-php/span/tree/1.1.4" + "source": "https://github.com/utopia-php/span/tree/1.1.5" }, - "time": "2026-02-13T10:58:12+00:00" + "time": "2026-02-13T18:00:11+00:00" }, { "name": "utopia-php/telemetry", diff --git a/src/DNS/Server.php b/src/DNS/Server.php index 85b0495..5345baa 100644 --- a/src/DNS/Server.php +++ b/src/DNS/Server.php @@ -179,6 +179,7 @@ protected function onPacket(string $buffer, string $ip, int $port, ?int $maxResp } catch (PartialDecodingException $e) { $this->handleError($e); + $span->set('level', 'warn'); $response = Message::response( $e->getHeader(), Message::RCODE_FORMERR, @@ -207,6 +208,7 @@ protected function onPacket(string $buffer, string $ip, int $port, ?int $maxResp $question = $query->questions[0] ?? null; if ($question === null) { + $span->set('level', 'warn'); $response = Message::response( $query->header, Message::RCODE_FORMERR, From a683c60a0c12898a38c3daca5de5cf6ba2e68fad Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 11 Mar 2026 14:03:06 +0000 Subject: [PATCH 2/2] Trim whitespace from domain names in Record and Question constructors Co-Authored-By: Claude Opus 4.6 --- src/DNS/Message/Question.php | 2 +- src/DNS/Message/Record.php | 2 +- tests/unit/DNS/Message/QuestionTest.php | 14 +++++++++ tests/unit/DNS/Message/RecordTest.php | 40 +++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/DNS/Message/Question.php b/src/DNS/Message/Question.php index 6cdfff1..a74c428 100644 --- a/src/DNS/Message/Question.php +++ b/src/DNS/Message/Question.php @@ -13,7 +13,7 @@ public function __construct( public int $type, public int $class = Record::CLASS_IN ) { - $this->name = strtolower($name); + $this->name = trim(strtolower($name)); } /** diff --git a/src/DNS/Message/Record.php b/src/DNS/Message/Record.php index 2618e7b..61988ec 100644 --- a/src/DNS/Message/Record.php +++ b/src/DNS/Message/Record.php @@ -120,7 +120,7 @@ public function __construct( public ?int $weight = null, public ?int $port = null ) { - $this->name = strtolower($name); + $this->name = trim(strtolower($name)); } /** diff --git a/tests/unit/DNS/Message/QuestionTest.php b/tests/unit/DNS/Message/QuestionTest.php index 9f100bb..4c1dea9 100644 --- a/tests/unit/DNS/Message/QuestionTest.php +++ b/tests/unit/DNS/Message/QuestionTest.php @@ -61,4 +61,18 @@ public function testDecodeHandlesCompressionPointer(): void $this->assertSame(Record::CLASS_IN, $parsedSecond->class); $this->assertSame(strlen($message), $offset); } + + public function testConstructorTrimsWhitespaceFromName(): void + { + $question = new Question(' www.example.com ', Record::TYPE_A, Record::CLASS_IN); + + $this->assertSame('www.example.com', $question->name); + } + + public function testConstructorTrimsTabsAndNewlinesFromName(): void + { + $question = new Question("\t\nwww.example.com\r\n", Record::TYPE_A, Record::CLASS_IN); + + $this->assertSame('www.example.com', $question->name); + } } diff --git a/tests/unit/DNS/Message/RecordTest.php b/tests/unit/DNS/Message/RecordTest.php index 9d3e2cb..72d87db 100644 --- a/tests/unit/DNS/Message/RecordTest.php +++ b/tests/unit/DNS/Message/RecordTest.php @@ -357,4 +357,44 @@ public function testDecodeSoaRecordRoundTrip(): void $this->assertSame($original, $encoded); } + + public function testConstructorTrimsWhitespaceFromName(): void + { + $record = new Record( + name: ' example.com ', + type: Record::TYPE_A, + class: Record::CLASS_IN, + ttl: 300, + rdata: '93.184.216.34' + ); + + $this->assertSame('example.com', $record->name); + } + + public function testConstructorTrimsTabsAndNewlinesFromName(): void + { + $record = new Record( + name: "\t\nexample.com\r\n", + type: Record::TYPE_A, + class: Record::CLASS_IN, + ttl: 300, + rdata: '93.184.216.34' + ); + + $this->assertSame('example.com', $record->name); + } + + public function testWithNameTrimsWhitespace(): void + { + $record = new Record( + name: 'example.com', + type: Record::TYPE_A, + class: Record::CLASS_IN, + ttl: 300, + rdata: '93.184.216.34' + ); + + $renamed = $record->withName(' other.com '); + $this->assertSame('other.com', $renamed->name); + } }