fix(client): fix security issues in adguardhome client (#4)
* fix(client): Check uint16 bounds for user provided port see https://github.com/csfreak/adguard-exporter/security/code-scanning/4 * fix(client): add option to disable tls verification defaults to false see https://github.com/csfreak/adguard-exporter/security/code-scanning/3
This commit is contained in:
parent
483435d1e9
commit
887ff4afea
@ -228,6 +228,9 @@ scrape_configs:
|
||||
|
||||
# Port to be used for the exporter
|
||||
-server_port string (optional) (default "9617")
|
||||
|
||||
# Disable TLS verification
|
||||
-insecure_tls_skip_verify bool (optional) (default "false")
|
||||
```
|
||||
|
||||
## Available Prometheus metrics
|
||||
|
@ -27,6 +27,7 @@ type Config struct {
|
||||
LogLimit string `config:"log_limit"`
|
||||
RDnsEnabled bool `config:"rdns_enabled"`
|
||||
PasswordFromFile bool `config:"password_from_file"`
|
||||
InsecureTLSSkipVerify bool `config:"insecure_tls_skip_verify"`
|
||||
}
|
||||
|
||||
func getDefaultConfig() *Config {
|
||||
@ -41,6 +42,7 @@ func getDefaultConfig() *Config {
|
||||
LogLimit: "1000",
|
||||
RDnsEnabled: true,
|
||||
PasswordFromFile: false,
|
||||
InsecureTLSSkipVerify: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,9 +39,9 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient method initializes a new AdGuard client.
|
||||
func NewClient(protocol, hostname, username, password, adport string, interval time.Duration, logLimit string, rdnsenabled bool) *Client {
|
||||
func NewClient(protocol, hostname, username, password, adport string, interval time.Duration, logLimit string, rdnsenabled bool, insecuretls bool) *Client {
|
||||
|
||||
temp, err := strconv.Atoi(adport)
|
||||
temp, err := strconv.ParseInt(adport, 10, 16)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -56,7 +56,9 @@ func NewClient(protocol, hostname, username, password, adport string, interval t
|
||||
interval: interval,
|
||||
logLimit: logLimit,
|
||||
httpClient: http.Client{
|
||||
Transport: &http.Transport{TLSClientConfig: GetTlsConfig()},
|
||||
Transport: &http.Transport{TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: insecuretls,
|
||||
}},
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
@ -263,12 +265,6 @@ func (c *Client) authenticateRequest(req *http.Request) {
|
||||
req.SetBasicAuth(c.username, c.password)
|
||||
}
|
||||
|
||||
func GetTlsConfig() *tls.Config {
|
||||
return &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
}
|
||||
|
||||
func isValidIp(ip string) bool {
|
||||
if net.ParseIP(ip) == nil {
|
||||
return false
|
||||
|
6
main.go
6
main.go
@ -26,14 +26,14 @@ func main() {
|
||||
|
||||
metrics.Init()
|
||||
|
||||
initAdguardClient(conf.AdguardProtocol, conf.AdguardHostname, conf.AdguardUsername, conf.AdguardPassword, conf.AdguardPort, conf.Interval, conf.LogLimit, conf.RDnsEnabled)
|
||||
initAdguardClient(conf.AdguardProtocol, conf.AdguardHostname, conf.AdguardUsername, conf.AdguardPassword, conf.AdguardPort, conf.Interval, conf.LogLimit, conf.RDnsEnabled, conf.InsecureTLSSkipVerify)
|
||||
initHttpServer(conf.ServerPort)
|
||||
|
||||
handleExitSignal()
|
||||
}
|
||||
|
||||
func initAdguardClient(protocol, hostname, username, password, port string, interval time.Duration, logLimit string, rdnsenabled bool) {
|
||||
client := adguard.NewClient(protocol, hostname, username, password, port, interval, logLimit, rdnsenabled)
|
||||
func initAdguardClient(protocol, hostname, username, password, port string, interval time.Duration, logLimit string, rdnsenabled bool, insecuretls bool) {
|
||||
client := adguard.NewClient(protocol, hostname, username, password, port, interval, logLimit, rdnsenabled, insecuretls)
|
||||
go client.Scrape()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user