Skip to content

Commit 1126e47

Browse files
committed
fix: variables should be set if their id and var_name match
Signed-off-by: Felipe Zipitria <[email protected]>
1 parent eb76d67 commit 1126e47

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/opt/modsecurity/configure-rules.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ if [ -n "${MANUAL_MODE}" ]; then
1717
return
1818
fi
1919

20-
20+
# Default config file path
2121
setup_conf_path="/etc/modsecurity.d/owasp-crs/crs-setup.conf"
2222

23+
# Accept optional config file
24+
if [ -n "${CONFIG_FILE}" ]; then
25+
setup_conf_path="${CONFIG_FILE}"
26+
fi
27+
2328
set_value() {
24-
local rule="${1}"
25-
local var_name="${2}"
26-
local tx_var_name="${3}"
27-
local var_value="${4}"
29+
rule="${1}"
30+
var_name="${2}"
31+
tx_var_name="${3}"
32+
var_value="${4}"
2833
echo "Configuring ${rule} for ${var_name} with ${tx_var_name}=${var_value}"
2934

3035
# For each rule, we do one pass to uncomment the rule (up to first blank line after the rule),
@@ -58,16 +63,13 @@ should_set() {
5863
}
5964

6065
can_set() {
61-
local rule="${1}"
62-
local tx_var_name="${2}"
66+
rule="${1}"
67+
tx_var_name="${2}"
6368

64-
if ! grep -q "id:${rule}" "${setup_conf_path}"; then
69+
if ! grep -q "id:${rule}" "${setup_conf_path}" -a ! grep -Eq "setvar:'?tx\.${tx_var_name}" "${setup_conf_path}"; then
6570
return 1
66-
elif ! grep -Eq "setvar:'?tx\.${tx_var_name}" "${setup_conf_path}"; then
67-
return 1
68-
else
69-
return 0
7071
fi
72+
return 0
7173
}
7274

7375
get_legacy() {
@@ -80,7 +82,7 @@ get_var_name() {
8082

8183
get_var_value() {
8284
# Get the variable name, produce "${<var name>}" and use eval to expand
83-
eval "echo $(echo "${1}" | awk -F'\|' '{print "${"$2"}"}')"
85+
eval "echo $(echo "${1}" | awk -F'\|' '{print "${"$2"}"}' || true)"
8486
}
8587

8688
get_rule() {

0 commit comments

Comments
 (0)