You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Query/DatagramTransportExecutor.php
+13-7Lines changed: 13 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -125,23 +125,29 @@ public function query($nameserver, Query $query)
125
125
});
126
126
127
127
$parser = $this->parser;
128
-
$loop->addReadStream($socket, function ($socket) use ($loop, $deferred, $query, $parser) {
128
+
$loop->addReadStream($socket, function ($socket) use ($loop, $deferred, $query, $parser, $request) {
129
129
// try to read a single data packet from the DNS server
130
130
// ignoring any errors, this is uses UDP packets and not a stream of data
131
131
$data = @\fread($socket, 512);
132
132
133
-
// we only react to the first message, so immediately remove socket from loop and close
134
-
$loop->removeReadStream($socket);
135
-
\fclose($socket);
136
-
137
133
try {
138
134
$response = $parser->parseMessage($data);
139
135
} catch (\Exception$e) {
140
-
// reject if we received an invalid message from remote server
141
-
$deferred->reject($e);
136
+
// ignore and await next if we received an invalid message from remote server
137
+
// this may as well be a fake response from an attacker (possible DOS)
142
138
return;
143
139
}
144
140
141
+
// ignore and await next if we received an unexpected response ID
142
+
// this may as well be a fake response from an attacker (possible cache poisoning)
143
+
if ($response->getId() !== $request->getId()) {
144
+
return;
145
+
}
146
+
147
+
// we only react to the first valid message, so remove socket from loop and close
148
+
$loop->removeReadStream($socket);
149
+
\fclose($socket);
150
+
145
151
if ($response->header->isTruncated()) {
146
152
$deferred->reject(new \RuntimeException('DNS query for ' . $query->name . ' failed: The server returned a truncated result for a UDP query, but retrying via TCP is currently not supported'));
0 commit comments