-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: support IP and UA rules #41
Conversation
…dd-rule # Conflicts: # controllers/rule.go
# Conflicts: # controllers/rule.go # go.sum # object/rule.go # service/proxy.go # service/waf.go # web/src/RuleEditPage.js # web/src/RuleListPage.js # web/src/backend/RuleBackend.js # web/src/components/IPRuleTable.js # web/src/components/WafRuleTable.js
|
||
func GetWAFRulesByIds(ids []string) string { | ||
// Get rules by id (owner/name) | ||
owners, names := util.GetOwnersAndNamesFromIds(ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mess with SQL. It's fragile.
Get all rules and do filtering in Go code
return true, nil | ||
} | ||
case "User-Agent": | ||
isMatch := checkUARule(rule.Expressions, r.UserAgent()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All isMatch needs to be isMatched
for _, rule := range rules { | ||
switch rule.Type { | ||
case "IP": | ||
isMatch := checkIPRule(rule.Expressions, clientIp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkIpRule
|
||
func createWAF() coraza.WAF { | ||
func createWAF(site *object.Site) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createWaf
} | ||
|
||
func UpdateWAF() { | ||
waf = createWAF() | ||
func UpdateWAFs() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wafs
</Col> | ||
</Row> | ||
) | ||
} | ||
<Row style={{marginTop: "20px"}}> | ||
{/* <Row style={{marginTop: "20px"}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code
@@ -150,24 +169,25 @@ class RuleEditPage extends React.Component { | |||
</Col> | |||
</Row> | |||
) | |||
} | |||
} */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add commented code, just remove it
@@ -49,6 +49,7 @@ type Site struct { | |||
OtherDomains []string `xorm:"varchar(500)" json:"otherDomains"` | |||
NeedRedirect bool `json:"needRedirect"` | |||
EnableWaf bool `json:"enableWaf"` | |||
WafRuleIds []string `xorm:"varchar(500)" json:"wafRuleIds"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WafRuleIds -> Rules
@@ -116,6 +117,87 @@ func redirectToHost(w http.ResponseWriter, r *http.Request, host string) { | |||
http.Redirect(w, r, targetUrl, http.StatusMovedPermanently) | |||
} | |||
|
|||
func checkRules(wafRuleIds []string, r *http.Request, clientIp string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clientIp is already in request I think?
return true, nil | ||
} | ||
|
||
func checkUARule(expressions []*object.Expression, userAgent string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct UaRule {
checkRule(expressions []*object.Expression, req http.Request) (string, string, error)
}
(string, string, error) is (action, reason, error)
action can be "Allow", "Block", etc.
reason is the formatted string
Allow or block requests by IP or UA