Skip to content

Commit

Permalink
fix: Preprocess the access to the request object in the policy (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
PokIsemaine committed Jul 17, 2023
1 parent 25011e0 commit 18f37ae
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func (e *Enforcer) enforce(matcher string, explains *[]string, rvals ...interfac
pvalsCopy := make([]string, len(pvals))
copy(pvalsCopy, pvals)
for i, pStr := range pvalsCopy {
pvalsCopy[i] = requestJsonReplace(pStr, rTokens, rvals)
pvalsCopy[i] = requestJsonReplace(util.EscapeAssertion(pStr), rTokens, rvals)
}
parameters.pVals = pvalsCopy
} else {
Expand Down

2 comments on commit 18f37ae

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 18f37ae Previous: 25011e0 Ratio
BenchmarkCachedRaw - ns/op 20.68 ns/op 20.92 ns/op 0.99
BenchmarkCachedRaw - B/op 0 B/op 0 B/op NaN
BenchmarkCachedRaw - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkCachedBasicModel - ns/op 232.3 ns/op 210.9 ns/op 1.10
BenchmarkCachedBasicModel - B/op 104 B/op 104 B/op 1
BenchmarkCachedBasicModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModel - ns/op 233.5 ns/op 210 ns/op 1.11
BenchmarkCachedRBACModel - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelSmall - ns/op 234.6 ns/op 226.6 ns/op 1.04
BenchmarkCachedRBACModelSmall - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelSmall - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelMedium - ns/op 257.2 ns/op 227 ns/op 1.13
BenchmarkCachedRBACModelMedium - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelMedium - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelLarge - ns/op 230.1 ns/op 214.1 ns/op 1.07
BenchmarkCachedRBACModelLarge - B/op 96 B/op 96 B/op 1
BenchmarkCachedRBACModelLarge - allocs/op 3 allocs/op 3 allocs/op 1
BenchmarkCachedRBACModelWithResourceRoles - ns/op 243 ns/op 211.7 ns/op 1.15
BenchmarkCachedRBACModelWithResourceRoles - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelWithResourceRoles - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelWithDomains - ns/op 252.1 ns/op 237.1 ns/op 1.06
BenchmarkCachedRBACModelWithDomains - B/op 120 B/op 120 B/op 1
BenchmarkCachedRBACModelWithDomains - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedABACModel - ns/op 3915 ns/op 3889 ns/op 1.01
BenchmarkCachedABACModel - B/op 1524 B/op 1521 B/op 1.00
BenchmarkCachedABACModel - allocs/op 18 allocs/op 18 allocs/op 1
BenchmarkCachedKeyMatchModel - ns/op 257.6 ns/op 247.6 ns/op 1.04
BenchmarkCachedKeyMatchModel - B/op 152 B/op 152 B/op 1
BenchmarkCachedKeyMatchModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelWithDeny - ns/op 248.2 ns/op 224.7 ns/op 1.10
BenchmarkCachedRBACModelWithDeny - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelWithDeny - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedPriorityModel - ns/op 246.6 ns/op 217.3 ns/op 1.13
BenchmarkCachedPriorityModel - B/op 104 B/op 104 B/op 1
BenchmarkCachedPriorityModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedWithEnforceContext - ns/op 458.7 ns/op 404.1 ns/op 1.14
BenchmarkCachedWithEnforceContext - B/op 240 B/op 240 B/op 1
BenchmarkCachedWithEnforceContext - allocs/op 5 allocs/op 5 allocs/op 1
BenchmarkCachedRBACModelMediumParallel - ns/op 222.2 ns/op 210.2 ns/op 1.06
BenchmarkCachedRBACModelMediumParallel - B/op 105 B/op 105 B/op 1
BenchmarkCachedRBACModelMediumParallel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkHasPolicySmall - ns/op 712.6 ns/op 644 ns/op 1.11
BenchmarkHasPolicySmall - B/op 150 B/op 150 B/op 1
BenchmarkHasPolicySmall - allocs/op 6 allocs/op 6 allocs/op 1
BenchmarkHasPolicyMedium - ns/op 728.6 ns/op 683.6 ns/op 1.07
BenchmarkHasPolicyMedium - B/op 157 B/op 157 B/op 1
BenchmarkHasPolicyMedium - allocs/op 6 allocs/op 6 allocs/op 1
BenchmarkHasPolicyLarge - ns/op 824 ns/op 720.8 ns/op 1.14
BenchmarkHasPolicyLarge - B/op 165 B/op 165 B/op 1
BenchmarkHasPolicyLarge - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkAddPolicySmall - ns/op 736.8 ns/op 665.7 ns/op 1.11
BenchmarkAddPolicySmall - B/op 152 B/op 152 B/op 1
BenchmarkAddPolicySmall - allocs/op 6 allocs/op 6 allocs/op 1
BenchmarkAddPolicyMedium - ns/op 1092 ns/op 829.1 ns/op 1.32
BenchmarkAddPolicyMedium - B/op 183 B/op 178 B/op 1.03
BenchmarkAddPolicyMedium - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkAddPolicyLarge - ns/op 1640 ns/op 1524 ns/op 1.08
BenchmarkAddPolicyLarge - B/op 428 B/op 457 B/op 0.94
BenchmarkAddPolicyLarge - allocs/op 9 allocs/op 9 allocs/op 1
BenchmarkRemovePolicySmall - ns/op 774.2 ns/op 690.6 ns/op 1.12
BenchmarkRemovePolicySmall - B/op 166 B/op 166 B/op 1
BenchmarkRemovePolicySmall - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkRemovePolicyMedium - ns/op 855.3 ns/op 763.3 ns/op 1.12
BenchmarkRemovePolicyMedium - B/op 178 B/op 178 B/op 1
BenchmarkRemovePolicyMedium - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkRemovePolicyLarge - ns/op 1693 ns/op 1665 ns/op 1.02
BenchmarkRemovePolicyLarge - B/op 286 B/op 287 B/op 1.00
BenchmarkRemovePolicyLarge - allocs/op 13 allocs/op 13 allocs/op 1
BenchmarkRaw - ns/op 20.79 ns/op 20.9 ns/op 0.99
BenchmarkRaw - B/op 0 B/op 0 B/op NaN
BenchmarkRaw - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkBasicModel - ns/op 4859 ns/op 4752 ns/op 1.02
BenchmarkBasicModel - B/op 1491 B/op 1489 B/op 1.00
BenchmarkBasicModel - allocs/op 17 allocs/op 17 allocs/op 1
BenchmarkRBACModel - ns/op 7529 ns/op 7239 ns/op 1.04
BenchmarkRBACModel - B/op 2039 B/op 2035 B/op 1.00
BenchmarkRBACModel - allocs/op 35 allocs/op 35 allocs/op 1
BenchmarkRBACModelSizes/small - ns/op 68295 ns/op 64127 ns/op 1.06
BenchmarkRBACModelSizes/small - B/op 19953 B/op 19955 B/op 1.00
BenchmarkRBACModelSizes/small - allocs/op 480 allocs/op 480 allocs/op 1
BenchmarkRBACModelSizes/medium - ns/op 840913 ns/op 646649 ns/op 1.30
BenchmarkRBACModelSizes/medium - B/op 191372 B/op 191249 B/op 1.00
BenchmarkRBACModelSizes/medium - allocs/op 4827 allocs/op 4827 allocs/op 1
BenchmarkRBACModelSizes/large - ns/op 9831044 ns/op 7535517 ns/op 1.30
BenchmarkRBACModelSizes/large - B/op 1903188 B/op 1901446 B/op 1.00
BenchmarkRBACModelSizes/large - allocs/op 48274 allocs/op 48229 allocs/op 1.00
BenchmarkRBACModelSmall - ns/op 80128 ns/op 76514 ns/op 1.05
BenchmarkRBACModelSmall - B/op 20095 B/op 20049 B/op 1.00
BenchmarkRBACModelSmall - allocs/op 615 allocs/op 615 allocs/op 1
BenchmarkRBACModelMedium - ns/op 767833 ns/op 737731 ns/op 1.04
BenchmarkRBACModelMedium - B/op 194234 B/op 194399 B/op 1.00
BenchmarkRBACModelMedium - allocs/op 6023 allocs/op 6022 allocs/op 1.00
BenchmarkRBACModelLarge - ns/op 9482976 ns/op 8543339 ns/op 1.11
BenchmarkRBACModelLarge - B/op 1948182 B/op 1947080 B/op 1.00
BenchmarkRBACModelLarge - allocs/op 60927 allocs/op 60884 allocs/op 1.00
BenchmarkRBACModelWithResourceRoles - ns/op 6191 ns/op 5986 ns/op 1.03
BenchmarkRBACModelWithResourceRoles - B/op 1823 B/op 1820 B/op 1.00
BenchmarkRBACModelWithResourceRoles - allocs/op 27 allocs/op 27 allocs/op 1
BenchmarkRBACModelWithDomains - ns/op 6761 ns/op 6623 ns/op 1.02
BenchmarkRBACModelWithDomains - B/op 1807 B/op 1803 B/op 1.00
BenchmarkRBACModelWithDomains - allocs/op 25 allocs/op 25 allocs/op 1
BenchmarkABACModel - ns/op 3705 ns/op 3727 ns/op 0.99
BenchmarkABACModel - B/op 1515 B/op 1511 B/op 1.00
BenchmarkABACModel - allocs/op 17 allocs/op 17 allocs/op 1
BenchmarkABACRuleModel - ns/op 4951313 ns/op 5138942 ns/op 0.96
BenchmarkABACRuleModel - B/op 1305613 B/op 1303790 B/op 1.00
BenchmarkABACRuleModel - allocs/op 40088 allocs/op 40088 allocs/op 1
BenchmarkKeyMatchModel - ns/op 7943 ns/op 7955 ns/op 1.00
BenchmarkKeyMatchModel - B/op 3027 B/op 3021 B/op 1.00
BenchmarkKeyMatchModel - allocs/op 37 allocs/op 37 allocs/op 1
BenchmarkRBACModelWithDeny - ns/op 9577 ns/op 9217 ns/op 1.04
BenchmarkRBACModelWithDeny - B/op 2448 B/op 2444 B/op 1.00
BenchmarkRBACModelWithDeny - allocs/op 49 allocs/op 49 allocs/op 1
BenchmarkPriorityModel - ns/op 5497 ns/op 5486 ns/op 1.00
BenchmarkPriorityModel - B/op 1740 B/op 1739 B/op 1.00
BenchmarkPriorityModel - allocs/op 22 allocs/op 22 allocs/op 1
BenchmarkRBACModelWithDomainPatternLarge - ns/op 32144 ns/op 29776 ns/op 1.08
BenchmarkRBACModelWithDomainPatternLarge - B/op 16618 B/op 16608 B/op 1.00
BenchmarkRBACModelWithDomainPatternLarge - allocs/op 164 allocs/op 164 allocs/op 1
BenchmarkRoleManagerSmall - ns/op 107531 ns/op 104542 ns/op 1.03
BenchmarkRoleManagerSmall - B/op 11953 B/op 11953 B/op 1
BenchmarkRoleManagerSmall - allocs/op 797 allocs/op 797 allocs/op 1
BenchmarkRoleManagerMedium - ns/op 1131397 ns/op 1077990 ns/op 1.05
BenchmarkRoleManagerMedium - B/op 125909 B/op 125909 B/op 1
BenchmarkRoleManagerMedium - allocs/op 8741 allocs/op 8741 allocs/op 1
BenchmarkRoleManagerLarge - ns/op 16046113 ns/op 13296752 ns/op 1.21
BenchmarkRoleManagerLarge - B/op 1349923 B/op 1349919 B/op 1.00
BenchmarkRoleManagerLarge - allocs/op 89741 allocs/op 89741 allocs/op 1
BenchmarkBuildRoleLinksWithPatternLarge - ns/op 8676248404 ns/op 7546230623 ns/op 1.15
BenchmarkBuildRoleLinksWithPatternLarge - B/op 5286035008 B/op 5285620520 B/op 1.00
BenchmarkBuildRoleLinksWithPatternLarge - allocs/op 60931010 allocs/op 60930738 allocs/op 1.00
BenchmarkBuildRoleLinksWithDomainPatternLarge - ns/op 234686311 ns/op 207452963 ns/op 1.13
BenchmarkBuildRoleLinksWithDomainPatternLarge - B/op 139575657 B/op 139539172 B/op 1.00
BenchmarkBuildRoleLinksWithDomainPatternLarge - allocs/op 1670246 allocs/op 1670243 allocs/op 1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - ns/op 8997878438 ns/op 7728443257 ns/op 1.16
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - B/op 5423956184 B/op 5422743952 B/op 1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - allocs/op 62541557 allocs/op 62541253 allocs/op 1.00
BenchmarkHasLinkWithPatternLarge - ns/op 14166 ns/op 13222 ns/op 1.07
BenchmarkHasLinkWithPatternLarge - B/op 7551 B/op 7537 B/op 1.00
BenchmarkHasLinkWithPatternLarge - allocs/op 111 allocs/op 111 allocs/op 1
BenchmarkHasLinkWithDomainPatternLarge - ns/op 737.4 ns/op 720.3 ns/op 1.02
BenchmarkHasLinkWithDomainPatternLarge - B/op 80 B/op 80 B/op 1
BenchmarkHasLinkWithDomainPatternLarge - allocs/op 5 allocs/op 5 allocs/op 1
BenchmarkHasLinkWithPatternAndDomainPatternLarge - ns/op 15063 ns/op 12809 ns/op 1.18
BenchmarkHasLinkWithPatternAndDomainPatternLarge - B/op 7550 B/op 7538 B/op 1.00
BenchmarkHasLinkWithPatternAndDomainPatternLarge - allocs/op 111 allocs/op 111 allocs/op 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.10.

Benchmark suite Current: 18f37ae Previous: 25011e0 Ratio
BenchmarkCachedBasicModel - ns/op 232.3 ns/op 210.9 ns/op 1.10
BenchmarkCachedRBACModel - ns/op 233.5 ns/op 210 ns/op 1.11
BenchmarkCachedRBACModelMedium - ns/op 257.2 ns/op 227 ns/op 1.13
BenchmarkCachedRBACModelWithResourceRoles - ns/op 243 ns/op 211.7 ns/op 1.15
BenchmarkCachedRBACModelWithDeny - ns/op 248.2 ns/op 224.7 ns/op 1.10
BenchmarkCachedPriorityModel - ns/op 246.6 ns/op 217.3 ns/op 1.13
BenchmarkCachedWithEnforceContext - ns/op 458.7 ns/op 404.1 ns/op 1.14
BenchmarkHasPolicySmall - ns/op 712.6 ns/op 644 ns/op 1.11
BenchmarkHasPolicyLarge - ns/op 824 ns/op 720.8 ns/op 1.14
BenchmarkAddPolicySmall - ns/op 736.8 ns/op 665.7 ns/op 1.11
BenchmarkAddPolicyMedium - ns/op 1092 ns/op 829.1 ns/op 1.32
BenchmarkRemovePolicySmall - ns/op 774.2 ns/op 690.6 ns/op 1.12
BenchmarkRemovePolicyMedium - ns/op 855.3 ns/op 763.3 ns/op 1.12
BenchmarkRBACModelSizes/medium - ns/op 840913 ns/op 646649 ns/op 1.30
BenchmarkRBACModelSizes/large - ns/op 9831044 ns/op 7535517 ns/op 1.30
BenchmarkRBACModelLarge - ns/op 9482976 ns/op 8543339 ns/op 1.11
BenchmarkRoleManagerLarge - ns/op 16046113 ns/op 13296752 ns/op 1.21
BenchmarkBuildRoleLinksWithPatternLarge - ns/op 8676248404 ns/op 7546230623 ns/op 1.15
BenchmarkBuildRoleLinksWithDomainPatternLarge - ns/op 234686311 ns/op 207452963 ns/op 1.13
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - ns/op 8997878438 ns/op 7728443257 ns/op 1.16
BenchmarkHasLinkWithPatternAndDomainPatternLarge - ns/op 15063 ns/op 12809 ns/op 1.18

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.