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 path regex check to locks #174

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
10 changes: 9 additions & 1 deletion rules/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import (
"fmt"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -166,11 +167,18 @@ func (e *v3Engine) SetWatcherWrapper(watcherWrapper WrapWatcher) {
e.watcherWrapper = watcherWrapper
}

// valid path patterns must be alphanumeric and may only contain select special characters (:/"'_.,*=-)
var validPath = regexp.MustCompile(`^[[:alnum:] \:\/\"\'\_\.\,\*\=\-]*$`)

func (e *v3Engine) AddRule(rule DynamicRule,
lockPattern string,
callback V3RuleTaskCallback,
options ...RuleOption) {
e.addRuleWithIface(rule, lockPattern, callback, options...)
if !validPath.MatchString(lockPattern) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not including check that the path contains "lock" since /crawler/compliance-engine /armada-ingress/:region/clusters/:clusterid/ingress_update paths don't contain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm, I think we should push to get that changed and then announce in armada-dev that this will be required from now on.

e.logger.Fatal("Path contains an invalid character")
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for else, when above is fatal?

e.addRuleWithIface(rule, lockPattern, callback, options...)
}
}

func (e *baseEngine) Stop() {
Expand Down