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

feat: support IP rate limiting #59

Merged
merged 5 commits into from
Aug 10, 2024

Conversation

love98ooo
Copy link
Contributor

@love98ooo love98ooo commented Aug 6, 2024

Fix: #58

P.S. update antd to ~4.24.0

@@ -131,6 +131,8 @@ func checkExpressions(expressions []*object.Expression, ruleType string) error {
return checkWafRule(values)
case "IP":
return checkIpRule(values)
case "IpRate":
Copy link
Contributor

Choose a reason for hiding this comment

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

Label is "IP Rate Limiting"

@@ -157,3 +159,19 @@ func checkIpRule(ipLists []string) error {
}
return nil
}

func checkIpRateRule(expressions []*object.Expression) error {
if len(expressions) != 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not allowed to be zero.


func checkIpRateRule(expressions []*object.Expression) error {
if len(expressions) != 1 {
return errors.New("IpRate rule should have only one expression")
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to limit this in frontend too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been limited in frontend.

@@ -86,7 +96,7 @@ class RuleEditPage extends React.Component {
{value: "WAF", text: "WAF"},
{value: "IP", text: "IP"},
{value: "User-Agent", text: "User-Agent"},
// {value: "frequency", text: "Frequency"},
{value: "IpRate", text: "IP Rate"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Label is "IP Rate Limiting"

{
this.state.rule.type === "IpRate" ? (
<IpRateRuleTable
title={"IP Rate"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Label is "IP Rate Limiting"

renderTable(table) {
const columns = [
{
title: "Name",
Copy link
Contributor

Choose a reason for hiding this comment

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

i18n

),
},
{
title: "Rate",
Copy link
Contributor

Choose a reason for hiding this comment

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

i18n

),
},
{
title: "Block Duration",
Copy link
Contributor

Choose a reason for hiding this comment

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

i18n

@@ -147,7 +147,7 @@ class UaRuleTable extends React.Component {
<div>
{this.props.title}&nbsp;&nbsp;&nbsp;&nbsp;
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{"Add"}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.restore()}>{"Restore Build-in User-Agent Rules"}</Button>
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.restore()}>{"Restore"}</Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Check all i18n

rule/rule.go Outdated
@@ -36,6 +36,10 @@ func CheckRules(ruleIds []string, r *http.Request) (string, string, error) {
ruleObj = &IpRule{}
case "WAF":
ruleObj = &WafRule{}
case "IpRate":
Copy link
Contributor

Choose a reason for hiding this comment

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

Label is "IP Rate Limiting"

@nomeguy nomeguy merged commit c085f09 into casbin:master Aug 10, 2024
8 checks passed
Copy link

🎉 This PR is included in version 1.29.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] support IP rate limiting rule
2 participants