Skip to content

Commit 43bd978

Browse files
committed
Validate ODoH padding length
Not really necessary, since responses are authenticated, but useful to spot broken server implementations.
1 parent f6baedb commit 43bd978

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

dnscrypt-proxy/oblivious_doh.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,16 @@ func (q ODoHQuery) decryptResponse(response []byte) ([]byte, error) {
185185
}
186186

187187
responseLength := binary.BigEndian.Uint16(responsePlaintext[0:2])
188-
if int(responseLength)+2 > len(responsePlaintext) {
188+
paddingOffset := 2 + int(responseLength)
189+
if paddingOffset+2 > len(responsePlaintext) {
190+
return nil, fmt.Errorf("Malformed response")
191+
}
192+
paddingLength := int(binary.BigEndian.Uint16(responsePlaintext[paddingOffset : paddingOffset+2]))
193+
if paddingOffset+2+paddingLength != len(responsePlaintext) {
189194
return nil, fmt.Errorf("Malformed response")
190195
}
191196
valid := 1
192-
for i := 4 + int(responseLength); i < len(responsePlaintext); i++ {
197+
for i := paddingOffset + 2; i < len(responsePlaintext); i++ {
193198
valid &= subtle.ConstantTimeByteEq(responsePlaintext[i], 0x00)
194199
}
195200
if valid != 1 {

0 commit comments

Comments
 (0)