Skip to content

Commit 3b196ce

Browse files
committed
fixes
1 parent 06201f9 commit 3b196ce

3 files changed

Lines changed: 32 additions & 22 deletions

File tree

engine/plugins/api/gleif/fuzzy.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (fc *fuzzyCompletions) lookup(e *et.Event, o *dbt.Entity, since time.Time)
7777
}
7878

7979
func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {
80+
exclusive := true
8081
var lei *general.Identifier
8182

8283
if leient := fc.plugin.orgEntityToLEI(e, orgent); leient != nil {
@@ -115,6 +116,7 @@ func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {
115116
if err := json.Unmarshal([]byte(resp.Body), &result); err != nil || len(result.Data) == 0 {
116117
return nil
117118
}
119+
exclusive = len(result.Data) == 1
118120

119121
for _, d := range result.Data {
120122
if fc.nameMatch(o, d.Attributes.Value) {
@@ -132,7 +134,7 @@ func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {
132134
}
133135

134136
rec, err := fc.plugin.getLEIRecord(lei)
135-
if err != nil || !fc.locMatch(e, orgent, rec) {
137+
if err != nil || (!exclusive && !fc.locMatch(e, orgent, rec)) {
136138
return nil
137139
}
138140

@@ -156,13 +158,19 @@ func (fc *fuzzyCompletions) nameMatch(o *org.Organization, name string) bool {
156158
}
157159

158160
func (fc *fuzzyCompletions) locMatch(e *et.Event, orgent *dbt.Entity, rec *leiRecord) bool {
159-
if edges, err := e.Session.Cache().OutgoingEdges(orgent, time.Time{}, "legal_address", "hq_address", "location"); err == nil {
161+
legal_addr := rec.Attributes.Entity.LegalAddress
162+
hq_addr := rec.Attributes.Entity.HeadquartersAddress
163+
164+
if edges, err := e.Session.Cache().OutgoingEdges(orgent,
165+
time.Time{}, "legal_address", "hq_address", "location"); err == nil {
160166
for _, edge := range edges {
161167
if a, err := e.Session.Cache().FindEntityById(edge.ToEntity.ID); err == nil && a != nil {
162-
if loc, ok := a.Asset.(*contact.Location); ok &&
163-
(loc.PostalCode == rec.Attributes.Entity.LegalAddress.PostalCode ||
164-
(loc.PostalCode == rec.Attributes.Entity.HeadquartersAddress.PostalCode)) {
165-
return true
168+
if loc, ok := a.Asset.(*contact.Location); ok {
169+
for _, p := range append([]leiAddress{legal_addr, hq_addr}, rec.Attributes.Entity.OtherAddresses...) {
170+
if loc.PostalCode == p.PostalCode {
171+
return true
172+
}
173+
}
166174
}
167175
}
168176
}
@@ -183,10 +191,12 @@ func (fc *fuzzyCompletions) locMatch(e *et.Event, orgent *dbt.Entity, rec *leiRe
183191
if edges, err := e.Session.Cache().OutgoingEdges(cr, time.Time{}, "location"); err == nil {
184192
for _, edge := range edges {
185193
if a, err := e.Session.Cache().FindEntityById(edge.ToEntity.ID); err == nil && a != nil {
186-
if loc, ok := a.Asset.(*contact.Location); ok &&
187-
(loc.PostalCode == rec.Attributes.Entity.LegalAddress.PostalCode ||
188-
(loc.PostalCode == rec.Attributes.Entity.HeadquartersAddress.PostalCode)) {
189-
return true
194+
if loc, ok := a.Asset.(*contact.Location); ok {
195+
for _, p := range append([]leiAddress{legal_addr, hq_addr}, rec.Attributes.Entity.OtherAddresses...) {
196+
if loc.PostalCode == p.PostalCode {
197+
return true
198+
}
199+
}
190200
}
191201
}
192202
}

engine/plugins/api/gleif/lei_record.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"errors"
1111
"fmt"
12+
"strings"
1213

1314
et "github.com/owasp-amass/amass/v4/engine/types"
1415
"github.com/owasp-amass/amass/v4/utils/net/http"
@@ -61,3 +62,14 @@ func (g *gleif) createLEIFromRecord(e *et.Event, orgent *dbt.Entity, lei *leiRec
6162
ExpirationDate: lei.Attributes.Registration.NextRenewalDate,
6263
})
6364
}
65+
66+
func (g *gleif) buildAddrFromLEIAddress(addr *leiAddress) string {
67+
street := strings.Join(addr.AddressLines, " ")
68+
69+
province := addr.Region
70+
if parts := strings.Split(province, "-"); len(parts) > 1 {
71+
province = parts[1]
72+
}
73+
74+
return fmt.Sprintf("%s %s %s %s %s", street, addr.City, province, addr.PostalCode, addr.Country)
75+
}

engine/plugins/api/gleif/org_lei.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"log/slog"
11-
"strings"
1211
"time"
1312

1413
"github.com/owasp-amass/amass/v4/engine/plugins/support"
@@ -86,17 +85,6 @@ func (g *gleif) updateOrgFromLEIRecord(e *et.Event, orgent *dbt.Entity, lei *lei
8685
_, _ = e.Session.Cache().CreateEntity(orgent)
8786
}
8887

89-
func (g *gleif) buildAddrFromLEIAddress(addr *leiAddress) string {
90-
street := strings.Join(addr.AddressLines, " ")
91-
92-
province := addr.Region
93-
if parts := strings.Split(province, "-"); len(parts) > 1 {
94-
province = parts[1]
95-
}
96-
97-
return fmt.Sprintf("%s %s %s %s %s", street, addr.City, province, addr.PostalCode, addr.Country)
98-
}
99-
10088
func (g *gleif) addAddress(e *et.Event, orgent *dbt.Entity, rel oam.Relation, addr string) error {
10189
loc := support.StreetAddressToLocation(addr)
10290
if loc == nil {

0 commit comments

Comments
 (0)