Skip to content

Commit

Permalink
fix: prevent SQL Injection Attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-star-l committed Aug 14, 2024
1 parent 9b4ab5e commit ba3d5ee
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions exporter/dorisexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package dorisexporter // import "github.com/open-telemetry/opentelemetry-collect

import (
"errors"
"regexp"
"time"

"go.opentelemetry.io/collector/config/configopaque"
Expand Down Expand Up @@ -61,6 +62,21 @@ func (cfg *Config) Validate() (err error) {
}
}

// Preventing SQL Injection Attacks
re := regexp.MustCompile(`^[a-zA-Z0-9_]+$`)
if !re.MatchString(cfg.Database) {
err = errors.Join(err, errors.New("database name must be alphanumeric and underscore"))
}
if !re.MatchString(cfg.Table.Logs) {
err = errors.Join(err, errors.New("logs table name must be alphanumeric and underscore"))
}
if !re.MatchString(cfg.Table.Traces) {
err = errors.Join(err, errors.New("traces table name must be alphanumeric and underscore"))
}
if !re.MatchString(cfg.Table.Metrics) {
err = errors.Join(err, errors.New("metrics table name must be alphanumeric and underscore"))
}

return err
}

Expand Down

0 comments on commit ba3d5ee

Please sign in to comment.