Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ Create `rules.conf` file in the root directory, WAFfl attaches rules at the comp

```conf
SecRuleEngine On

SecDefaultAction "phase:1,log,auditlog,pass"
SecDefaultAction "phase:2,log,auditlog,pass"
SecAction \
"id:900990,\
phase:1,\
pass,\
t:none,\
nolog,\
tag:'OWASP_CRS',\
ver:'OWASP_CRS/4.13.0-dev',\
setvar:tx.crs_setup_version=4130"
SecRule REQUEST_URI "@rx admin" "id:1,phase:1,deny,status:401"
```

Expand Down
12 changes: 11 additions & 1 deletion README_Zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@

```conf
SecRuleEngine On

SecDefaultAction "phase:1,log,auditlog,pass"
SecDefaultAction "phase:2,log,auditlog,pass"
SecAction \
"id:900990,\
phase:1,\
pass,\
t:none,\
nolog,\
tag:'OWASP_CRS',\
ver:'OWASP_CRS/4.13.0-dev',\
setvar:tx.crs_setup_version=4130"
SecRule REQUEST_URI "@rx admin" "id:1,phase:1,deny,status:401"
```

Expand Down
18 changes: 8 additions & 10 deletions src/api/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,24 @@ def __rule_append(self, rule_path: Path, reason: Optional[str] = None) -> None:
if RULE_INCLUSION_PATTERN.search(line.rstrip()):
filename = RULE_INCLUSION_PATTERN.search(line.rstrip()).group(2)
modified_payload = line.rstrip().replace(filename, f"{INCLUDE}{filename}")
print(line.rstrip())
print(modified_payload)
self.rules.append(f"{modified_payload}")
else:
self.rules.append(line.rstrip())

# 處理規則內容
if RULE_PATTERN.match(line):
self.rules.append("\n")
self.rules.append(f"# {reason}") if reason is not None else None

# 處理檔案引入的路徑
if RULE_INCLUSION_PATTERN.match(content):
filename = RULE_INCLUSION_PATTERN.search(content).group(2)
modified_payload = content.replace(filename, f"{INCLUDE}{filename}")
self.rules.append(f"{modified_payload}")
self.rules.append(f"\n{modified_payload}")
else:
self.rules.append(f"{content}")
self.rules.append(f"\n{content}")
multiline = True

if content == "chain\"":
if content == "chain\"" or content == "\"chain\"":
continue

if not content.endswith("\\"):
Expand Down Expand Up @@ -137,10 +134,11 @@ def extract_rule(self, option: RuleAppendType = RuleAppendType.ALL) -> None:
"""
option_manifest: Dict[object] = {RuleAppendType.ALL: self.__all, RuleAppendType.MAPPING: self.__mapping}

for root, _, files in os.walk(self.source):
for file in files:
if file.endswith(".conf"):
option_manifest[option](root, file)
inclusion_order = sorted(os.walk(self.source).__next__()[2])

for file in inclusion_order:
if file.endswith(".conf"):
option_manifest[option](INCLUDE, file)

def rule_dump(self, overwrite: bool = False) -> None:
"""
Expand Down