Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for feature label values #199

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
var (
version = "" // Must not be const, set using ldflags at build time
validFeatureNameRe = regexp.MustCompile(`^([-.\w]*)?[A-Za-z0-9]$`)
validFeatureValRe = regexp.MustCompile(`^(([A-Za-z0-9][-.\w]*)?[A-Za-z0-9])?$`)
)

// package loggers
Expand Down Expand Up @@ -359,20 +360,28 @@ func getFeatureLabels(source source.FeatureSource) (labels Labels, err error) {
if err != nil {
return nil, err
}
for k := range features {
// Validate label
for k, v := range features {
// Validate label name
if !validFeatureNameRe.MatchString(k) {
stderrLogger.Printf("Invalid feature name '%s', ignoring...", k)
continue
}

prefix := source.Name() + "-"
switch source.(type) {
case local.Source:
// Do not prefix labels from the hooks
prefix = ""
}
labels[fmt.Sprintf("%s%s", prefix, k)] = fmt.Sprintf("%v", features[k])
label := prefix + k

// Validate label value
value := fmt.Sprintf("%v", v)
if !validFeatureValRe.MatchString(value) {
stderrLogger.Printf("Invalid value '%s' for label '%s', ignoring...", value, label)
continue
}

labels[label] = value
}
return labels, nil
}
Expand Down