Skip to content

Commit f3484a4

Browse files
committed
chore: whitelist the domains
1 parent 9ae48ea commit f3484a4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

main.go

+25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,31 @@ import (
99
"github.com/miekg/dns"
1010
)
1111

12+
var whitelistedDomains = []string{
13+
"github.com",
14+
"nginx.com",
15+
}
16+
17+
// Function to check if the domain is whitelisted
18+
func isWhitelistedDomain(domain string) bool {
19+
for _, whitelisted := range whitelistedDomains {
20+
if strings.HasSuffix(domain, whitelisted) {
21+
return true
22+
}
23+
}
24+
return false
25+
}
26+
27+
// Function to forward DNS query to external DNS server
1228
func forwardToExternalDNS(q dns.Question) ([]dns.RR, error) {
29+
// Extract the domain name from the question
30+
domain := strings.TrimSuffix(q.Name, ".")
31+
32+
// Check if the domain is whitelisted
33+
if !isWhitelistedDomain(domain) {
34+
return nil, fmt.Errorf("domain %s is not whitelisted", domain)
35+
}
36+
1337
// Query the external DNS server (e.g., 1.1.1.1)
1438
client := new(dns.Client)
1539
message := new(dns.Msg)
@@ -23,6 +47,7 @@ func forwardToExternalDNS(q dns.Question) ([]dns.RR, error) {
2347
return resp.Answer, nil
2448
}
2549

50+
2651
func parseQuery(m *dns.Msg, qdns *QuickDNSResolver) {
2752
for _, q := range m.Question {
2853
println("Query: ", q.Name, q.Qtype, q.Qclass)

0 commit comments

Comments
 (0)