Skip to content

Commit 306e2e4

Browse files
authored
Merge pull request #22 from mxlint/new-rules-project-settings-security-bza
2 parents fc135cf + ed52fa9 commit 306e2e4

4 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# METADATA
2+
# scope: package
3+
# title: Hash algorithm
4+
# description: Hashs algorithms BCrypt and SSHA256 are considered to be the safest for data encryption.
5+
# authors:
6+
# - Bart Zantingh <bart.zantingh@nl.abnamro.com>
7+
# related_resources:
8+
# - https://docs.mendix.com/refguide/security#hashing-algorithms
9+
# custom:
10+
# category: Security
11+
# rulename: HashAlgorithm
12+
# severity: HIGH
13+
# rulenumber: "001_0007"
14+
# remediation: Set the app's hash algorithm (App Settings > Runtime) to BCrypt or SSHA256.
15+
# input: "Settings$ProjectSettings.yaml"
16+
package app.mendix.project_settings.hash_algorithm
17+
18+
import rego.v1
19+
20+
annotation := rego.metadata.chain()[1].annotations
21+
22+
default allow := false
23+
24+
allow if count(errors) == 0
25+
26+
errors contains error if {
27+
not input.Settings.HashAlgorithm == "BCrypt"
28+
not input.Settings.HashAlgorithm == "SSHA256"
29+
30+
error := sprintf(
31+
"[%v, %v, %v] The application uses the %v hash algorithm, which is not recommended",
32+
[
33+
annotation.custom.severity,
34+
annotation.custom.category,
35+
annotation.custom.rulenumber,
36+
input.Settings.HashAlgorithm,
37+
],
38+
)
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package app.mendix.project_settings.hash_algorithm_test
2+
3+
import data.app.mendix.project_settings.hash_algorithm
4+
import rego.v1
5+
6+
# Test data
7+
bcrypt := {"Settings": {
8+
"$Type": "Settings$ModelSettings",
9+
"HashAlgorithm": "BCrypt",
10+
}}
11+
12+
ssha256 := {"Settings": {
13+
"$Type": "Settings$ModelSettings",
14+
"HashAlgorithm": "SSHA256",
15+
}}
16+
17+
sha256 := {"Settings": {
18+
"$Type": "Settings$ModelSettings",
19+
"HashAlgorithm": "SHA256",
20+
}}
21+
22+
md5 := {"Settings": {
23+
"$Type": "Settings$ModelSettings",
24+
"HashAlgorithm": "MD5",
25+
}}
26+
27+
# Test cases
28+
test_should_allow_when_build_version_in_allowed_list if {
29+
hash_algorithm.allow with input as bcrypt
30+
hash_algorithm.allow with input as ssha256
31+
}
32+
33+
test_should_deny_when_build_version_not_in_allowed_list if {
34+
not hash_algorithm.allow with input as sha256
35+
not hash_algorithm.allow with input as md5
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# METADATA
2+
# scope: package
3+
# title: Check security on user roles
4+
# description: Security should be checked for each user role, to make sure users can only access the minimum amount of data
5+
# authors:
6+
# - Bart Zantingh <bart.zantingh@nl.abnamro.com>
7+
# custom:
8+
# category: Security
9+
# rulename: CheckSecurityOnUserRoles
10+
# severity: HIGH
11+
# rulenumber: "001_0008"
12+
# remediation: Check security for all user roles
13+
# input: "Security$ProjectSecurity.yaml"
14+
package app.mendix.project_settings.check_security_on_user_roles
15+
16+
import rego.v1
17+
18+
annotation := rego.metadata.chain()[1].annotations
19+
20+
default allow := false
21+
22+
allow if count(errors) == 0
23+
24+
errors contains error if {
25+
some user_role in input.UserRoles
26+
not user_role.CheckSecurity
27+
28+
error := sprintf(
29+
"[%v, %v, %v] User role %v is not checked for security",
30+
[
31+
annotation.custom.severity,
32+
annotation.custom.category,
33+
annotation.custom.rulenumber,
34+
user_role.Name,
35+
],
36+
)
37+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package app.mendix.project_settings.check_security_on_user_roles_test
2+
3+
import data.app.mendix.project_settings.check_security_on_user_roles
4+
import rego.v1
5+
6+
# Test data
7+
check_for_security := {"UserRoles": [{
8+
"CheckSecurity": true,
9+
"Name": "Administrator",
10+
}]}
11+
12+
not_check_for_security := {"UserRoles": [{
13+
"CheckSecurity": false,
14+
"Name": "Administrator",
15+
}]}
16+
17+
# Test cases
18+
test_should_allow_when_checking_user_roles_for_security if {
19+
check_security_on_user_roles.allow with input as check_for_security
20+
}
21+
22+
test_should_deny_when_not_checking_user_roles_for_security if {
23+
not check_security_on_user_roles.allow with input as not_check_for_security
24+
}

0 commit comments

Comments
 (0)