Skip to content

Commit 2de636f

Browse files
Merge pull request #391 from step-security/fix-wildcard-resolution
Fix bug with wildcard resolution
2 parents f236e57 + 22f4ba0 commit 2de636f

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func refreshDNSEntries(ctx context.Context, iptables *Firewall, allowedEndpoints
270270
}
271271

272272
// add to cache with new TTL
273-
dnsProxy.Cache.Set(domainName, answer)
273+
dnsProxy.Cache.Set(domainName, answer, false)
274274

275275
WriteLog(fmt.Sprintf("domain resolved: %s, ip address: %s, TTL: %d", domainName, answer.Data, answer.TTL))
276276
}

cache.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
)
77

88
type Element struct {
9-
Value *Answer
10-
TimeAdded int64
9+
Value *Answer
10+
TimeAdded int64
11+
IsWildcardDomain bool
1112
}
1213

1314
type Cache struct {
@@ -32,7 +33,7 @@ func (cache *Cache) Get(k string) (*Element, bool) {
3233
return nil, false
3334
}
3435

35-
if cache.egressPolicy == EgressPolicyAudit {
36+
if cache.egressPolicy == EgressPolicyAudit || element.IsWildcardDomain {
3637
// TTL is in seconds
3738
// if now minus time added is greater than TTL, return nil, so new DNS request is made
3839
if time.Now().Unix()-element.TimeAdded > int64(element.Value.TTL) {
@@ -51,12 +52,13 @@ func (cache *Cache) Get(k string) (*Element, bool) {
5152
}
5253
}
5354

54-
func (cache *Cache) Set(k string, v *Answer) {
55+
func (cache *Cache) Set(k string, v *Answer, isWildcardDomain bool) {
5556
cache.mutex.Lock()
5657

5758
cache.elements[k] = Element{
58-
Value: v,
59-
TimeAdded: time.Now().Unix(),
59+
Value: v,
60+
TimeAdded: time.Now().Unix(),
61+
IsWildcardDomain: isWildcardDomain,
6062
}
6163

6264
cache.mutex.Unlock()

dnsproxy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (proxy *DNSProxy) getIPByDomain(domain string) (string, error) {
206206

207207
// return an ip address, so calling process calls the ip address
208208
// the call will be blocked by the firewall
209-
proxy.Cache.Set(domain, &Answer{Name: domain, TTL: math.MaxInt32, Data: StepSecuritySinkHoleIPAddress})
209+
proxy.Cache.Set(domain, &Answer{Name: domain, TTL: math.MaxInt32, Data: StepSecuritySinkHoleIPAddress}, false)
210210

211211
go proxy.ApiClient.sendDNSRecord(proxy.CorrelationId, proxy.Repo, domain, StepSecuritySinkHoleIPAddress)
212212

@@ -227,7 +227,7 @@ func (proxy *DNSProxy) getIPByDomain(domain string) (string, error) {
227227
}
228228
}
229229

230-
proxy.Cache.Set(domain, answer)
230+
proxy.Cache.Set(domain, answer, matchesAnyWildcard)
231231

232232
go WriteLog(fmt.Sprintf("domain resolved: %s, ip address: %s, TTL: %d", domain, answer.Data, answer.TTL))
233233

@@ -259,7 +259,7 @@ func (proxy *DNSProxy) processTypeA(q *dns.Question, requestMsg *dns.Msg) (*dns.
259259
return nil, err
260260
}
261261

262-
proxy.Cache.Set(q.Name, &Answer{Name: q.Name, TTL: math.MaxInt32, Data: "8.8.8.8"})
262+
proxy.Cache.Set(q.Name, &Answer{Name: q.Name, TTL: math.MaxInt32, Data: "8.8.8.8"}, false)
263263

264264
return &rr, nil
265265
}

0 commit comments

Comments
 (0)