When using DNS-over-HTTPS with GET requests, DNS queries must be encoded using base64url encoding. This requirement exists for several important technical reasons:
DNS queries are binary data structures that contain information about the domain name being queried, the type of record requested (A, AAAA, MX, etc.), and other metadata. URLs, however, are text-based and have restrictions on what characters they can contain.
Standard Base64 encoding uses characters like '+' and '/' which have special meanings in URLs:
- '+' is interpreted as a space in URL query parameters
- '/' is interpreted as a path separator
Base64url encoding solves this by:
- Replacing '+' with '-'
- Replacing '/' with '_'
- Optionally omitting padding '=' characters
The DNS-over-HTTPS specification (RFC 8484) mandates the use of base64url encoding for DNS queries transmitted via GET requests to ensure interoperability between different DoH implementations.
- A DNS query for "example.com" is represented as binary data
- This binary data is encoded using base64url encoding
- The resulting string is safe to use in a URL query parameter
For example:
Binary DNS Query → Base64url Encoding → URL Parameter
[0x12, 0x34, ...] → "q80BAAAB..." → ?dns=q80BAAAB...
- GET Requests: DNS queries MUST be base64url-encoded
- POST Requests: DNS queries are sent as binary data in the request body (no encoding needed)
If you prefer to avoid base64url encoding entirely, you can use POST requests to send raw binary DNS queries. This method:
- Eliminates the need for any encoding transformations
- Sends the DNS query directly as binary data in the request body
- Still complies with RFC 8484 for DNS-over-HTTPS
- Requires setting the
Content-Type: application/dns-messageheader
Example with curl:
curl -H "Content-Type: application/dns-message" \
--data-binary @query.dns \
https://your-doh-endpoint/dns-queryThis approach is particularly useful when:
- Working with clients that don't have base64 encoding capabilities
- You want to reduce processing overhead
- You prefer to work with raw binary data
Many programming languages provide built-in functions for base64url encoding:
- JavaScript:
base64url.encode() - Python:
base64.urlsafe_b64encode() - Command-line:
openssl base64 -url
This encoding requirement ensures that DNS queries can be safely transmitted over HTTPS while maintaining compatibility with web standards and the DoH protocol specification.