mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2026-07-23 18:15:44 +00:00
Fix data races, nil-record panics, scanner SSRF, log date layout, shutdown timeouts, and enable stricter linters (#54)
High (behavioral bugs):
- service.Geo: add RLock on lookups, handle Reload error, keep old DBs on failure
- models.GeoDB.Reload: open new DBs before closing old ones (no reader gap)
- router: guard nil geo records (404 instead of 500) in geo.go, generic.go, dns.go
- router/port_scanner: reject undetermined client IPs (nil->localhost dial)
- internal/httputils: fix access log date layout (02/Jan/2006, not literal Nov)
- server/quic: log.Printf instead of log.Fatal in request handler
Medium:
- server/*: 10s shutdown timeout; SIGTERM drains servers before closing geo DBs
- httputils: Clone() request headers instead of mutating the live map; strings.Builder
- setting/app: handle all os.Stat errors; fix "truster" typos; use errors.New;
remove dead Token field
- cmd: errors.Is for sentinel checks; os.Stderr; log.Fatal instead of panic;
pass http.Handler by value (not pointer-to-interface)
- resolver: validate config at startup (pre-parse RRs, validate IPs); check WriteMsg
errors; Setup returns error
Low:
- .golangci.yaml: enable errcheck, govet, errorlint; fix all resulting findings
- server/tls: explicit TLSConfig{MinVersion: tls.VersionTLS12}
- router/dns: label-exact vhost suffix check, strip port; template.Must
- models: errors.Join instead of %s on []error
- service/geo_test: race-regression test (concurrent lookups during Reload)
- README: Go >= 1.25; fix latent test bug (store.Add->Set in dns_test.go)
This commit is contained in:
+29
-10
@@ -87,15 +87,24 @@ func getGeoAsString(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
field := strings.ToLower(ctx.Params.ByName("field"))
|
||||
record := geoSvc.LookUpCity(net.ParseIP(ctx.ClientIP()))
|
||||
if record == nil {
|
||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||
return
|
||||
}
|
||||
|
||||
field := strings.ToLower(ctx.Params.ByName("field"))
|
||||
if field == "" {
|
||||
ctx.String(http.StatusOK, geoCityRecordToString(record))
|
||||
} else if g, ok := geoOutput[field]; ok {
|
||||
ctx.String(http.StatusOK, g.format(record))
|
||||
} else {
|
||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||
return
|
||||
}
|
||||
|
||||
g, ok := geoOutput[field]
|
||||
if !ok {
|
||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||
return
|
||||
}
|
||||
ctx.String(http.StatusOK, g.format(record))
|
||||
}
|
||||
|
||||
func getASNAsString(ctx *gin.Context) {
|
||||
@@ -103,15 +112,25 @@ func getASNAsString(ctx *gin.Context) {
|
||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||
return
|
||||
}
|
||||
field := strings.ToLower(ctx.Params.ByName("field"))
|
||||
|
||||
record := geoSvc.LookUpASN(net.ParseIP(ctx.ClientIP()))
|
||||
if record == nil {
|
||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||
return
|
||||
}
|
||||
|
||||
field := strings.ToLower(ctx.Params.ByName("field"))
|
||||
if field == "" {
|
||||
ctx.String(http.StatusOK, geoASNRecordToString(record))
|
||||
} else if g, ok := asnOutput[field]; ok {
|
||||
ctx.String(http.StatusOK, g.format(record))
|
||||
} else {
|
||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||
return
|
||||
}
|
||||
|
||||
g, ok := asnOutput[field]
|
||||
if !ok {
|
||||
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||
return
|
||||
}
|
||||
ctx.String(http.StatusOK, g.format(record))
|
||||
}
|
||||
|
||||
func geoCityRecordToString(record *models.GeoRecord) string {
|
||||
|
||||
Reference in New Issue
Block a user