256 Commits

Author SHA1 Message Date
fab
edd338a311
Update import_haproxy_waf.py 2025-02-28 11:21:33 +01:00
fab
068c4c59b4
Update import_apache_waf.py 2025-02-28 11:20:17 +01:00
fab
676c53d383
Update json2nginx.py 2025-02-28 11:19:32 +01:00
fab
1a3c968ba2
Update json2apache.py 2025-02-28 11:17:52 +01:00
fab
4591dfa52e
Update owasp2json.py 2025-02-28 11:16:46 +01:00
fab
95b1b4a784
Update json2haproxy.py 2025-02-28 11:15:14 +01:00
github-actions[bot]
c2306aca23 Update: [Fri Feb 28 10:03:59 UTC 2025] 2025-02-28 10:03:59 +00:00
fab
b0a1204ea7
Update json2haproxy.py 2025-02-28 11:03:13 +01:00
github-actions[bot]
cc2b6d768f Update: [Fri Feb 28 10:01:01 UTC 2025] 2025-02-28 10:01:01 +00:00
fab
a6307b5cf6
Update json2haproxy.py 2025-02-28 11:00:40 +01:00
github-actions[bot]
dc731a715c Update: [Fri Feb 28 09:59:23 UTC 2025] 2025-02-28 09:59:23 +00:00
fab
9e85df0fee
Update json2haproxy.py
feat: Implement OWASP CRS to HAProxy WAF conversion with enhanced features

This commit introduces significant improvements to the script for converting OWASP Core Rule Set (CRS) rules into HAProxy Web Application Firewall (WAF) configurations.

Key changes include:

- **Expanded Operator Mapping:** Added more comprehensive mappings between ModSecurity operators and HAProxy equivalents, improving the translation of OWASP rules.

- **Location-Based ACLs:** Implemented support for inspecting different request parameters (User-Agent, Request-URI, Host, etc.) based on the `location` field in the JSON rules, increasing the WAF's coverage.

- **Rule Prioritization:** Introduced rule prioritization based on severity (high, medium, low), allowing for different actions (deny, log, tarpit) to be triggered based on the assessed risk.

- **Improved Regex Handling:** Enhanced regex validation to identify and skip overly complex or invalid patterns, preventing performance issues and potential errors.

- **Clearer ACL Logic:** Restructured the generated `waf.acl` file for better organization, separating ACL definitions from deny logic and grouping rules by request parameter location.

- **Detailed Logging:** Improved logging to provide more specific information about skipped rules, invalid patterns, and other issues, aiding in debugging and configuration.

- **Integer Comparison:** Added capability to use http-request to perform integer comparison instead of strings in the rules.

These enhancements result in a more effective, maintainable, and configurable HAProxy WAF implementation based on the OWASP CRS.

Please note that thorough testing and tuning are still crucial to ensure the WAF is working correctly and not causing false positives.

This commit addresses the following issues:

- Addresses overly aggressive rules causing false positives.
- Implements missing support for ModSecurity operators.
- Enables inspection of request parameters beyond the User-Agent header.
- Provides a more organized and maintainable HAProxy WAF configuration.
2025-02-28 10:58:24 +01:00
github-actions[bot]
85d732ced9 Update: [Fri Feb 28 01:41:36 UTC 2025] 2025-02-28 01:41:36 +00:00
github-actions[bot]
87d028e20c Update: [Thu Feb 27 01:41:26 UTC 2025] 2025-02-27 01:41:26 +00:00
github-actions[bot]
02b100fdb2 Update: [Wed Feb 26 00:26:23 UTC 2025] 2025-02-26 00:26:24 +00:00
github-actions[bot]
9f8a891fd8 Update: [Tue Feb 25 00:26:42 UTC 2025] 2025-02-25 00:26:42 +00:00
github-actions[bot]
9554870ec8 Update: [Mon Feb 24 00:27:16 UTC 2025] 2025-02-24 00:27:16 +00:00
fab
6070f591ae
Update README.md 2025-02-23 22:33:08 +01:00
github-actions[bot]
2c1fbc2853 Update: [Sun Feb 23 00:28:29 UTC 2025] 2025-02-23 00:28:29 +00:00
github-actions[bot]
1968c16e46 Update: [Sat Feb 22 10:52:46 UTC 2025] 2025-02-22 10:52:46 +00:00
fab
f90caf30d9
Update json2apache.py
JSON bug fixed.
2025-02-22 11:41:33 +01:00
fab
fe8ca8c3d2
Merge pull request #13 from fabriziosalmi/codeflash/optimize-sanitize_pattern-m6xpxrl4
️ Speed up function `sanitize_pattern` by 631%
2025-02-09 15:30:59 +01:00
codeflash-ai[bot]
b08285fd76
️ Speed up function sanitize_pattern by 631%
Here's an optimized version of the given Python program for better runtime efficiency.
2025-02-09 14:27:36 +00:00
fab
75cdaa01b9
Merge pull request #10 from fabriziosalmi/codeflash/optimize-validate_regex-m6xoy1wp
️ Speed up function `validate_regex` by 162%
2025-02-09 15:15:00 +01:00
fab
870da8e1c9
Merge pull request #11 from fabriziosalmi/codeflash/optimize-validate_regex-m6xp4bpf
️ Speed up function `validate_regex` by 2,003%
2025-02-09 15:14:42 +01:00
fab
fb284892f1
Merge pull request #12 from fabriziosalmi/codeflash/optimize-sanitize_pattern-m6xp6cvk
️ Speed up function `sanitize_pattern` by 11,547%
2025-02-09 15:14:24 +01:00
codeflash-ai[bot]
17faa1f1b9
️ Speed up function sanitize_pattern by 11,547%
I've analyzed the script provided and I'll make some optimizations to improve its runtime performance while ensuring the functionality remains the same. Let's break it down step-by-step.

### Improvements.
1. **Avoid Redundant Checks:** Optimize by eliminating unnecessary repetitive checks.
2. **Combining String Operations:** Combine string operations to minimize calls.
3. **Caching Compiled Patterns:** If re.escape or re.compile are used multiple times for the same pattern, cache the results to avoid recomputing them.

Here’s the optimized version of the script.



### Summary of changes.
1. **LRU Caching**.
   - Used `functools.lru_cache` to cache results of `_compile_pattern` and `_sanitize_pattern` for improved performance on repetitive calls.
2. **Removed Redundant Condition**.
   - Moved repeated checks and operations within a single `if` block to simplify the flow and eliminate unnecessary calls.
3. **Centralized Pattern Validation**.
   - Centralized the regex validation and escaping in `_sanitize_pattern` function to minimize redundancy.

These changes should optimize your program's performance by reducing redundant computations and leveraging caching mechanisms. The functionality remains unchanged and will return the same values as before.
2025-02-09 14:06:18 +00:00
codeflash-ai[bot]
a54f33e097
️ Speed up function validate_regex by 2,003%
### Explanation.

1. **Caching with lru_cache**.
   - By using `functools.lru_cache`, the function `validate_regex` now caches the results of previous calls. If the same pattern is validated multiple times, the cached result is returned immediately, significantly improving the performance for repeated patterns. This change optimizes the runtime without altering the function's behavior.
2025-02-09 14:04:43 +00:00
codeflash-ai[bot]
7eef3f8fa7
️ Speed up function validate_regex by 162%
Here is an optimized version of the provided Python program. The optimizations focus on improving the I/O operations, avoiding unnecessary checks, and caching the regex pattern validation.



### Explanation of Optimizations.
1. **Caching with `@lru_cache`**: The `validate_regex` function is wrapped with `@lru_cache` to cache the results of previously validated regex patterns. This prevents repeated compilation of the same regex patterns.
2. **Reading the JSON file**: I/O operations were optimized by using the `with` statement to handle file reading and writing.
3. **Avoiding repeated checks**: The unsupported patterns are checked just once per pattern, eliminating redundant operations.
4. **Batch writing**: All rules are collected in a list and written to the output file in a single operation, reducing the overhead of multiple write operations.
2025-02-09 13:59:51 +00:00
fab
1a4a2d4e42
Merge pull request #9 from fabriziosalmi/codeflash/optimize-validate_regex-m6xkx22f
️ Speed up function `validate_regex` by 9,172%
2025-02-09 13:14:25 +01:00
codeflash-ai[bot]
a3104b23c1
️ Speed up function validate_regex by 9,172%
Changes made for optimization.
1. Added `functools.lru_cache` decorator to cache results of `validate_regex` function calls. This ensures that repeated validations of the same pattern are resolved quickly and avoid redundant regex compilations.
2025-02-09 12:07:05 +00:00
github-actions[bot]
1a98411808 Update: [Sun Feb 9 00:27:59 UTC 2025] 2025-02-09 00:27:59 +00:00
github-actions[bot]
7d2f1248c7 Update: [Sat Feb 8 00:25:04 UTC 2025] 2025-02-08 00:25:04 +00:00
github-actions[bot]
cf21042b9c Update: [Fri Feb 7 00:25:52 UTC 2025] 2025-02-07 00:25:52 +00:00
github-actions[bot]
1cebb95fc3 Update: [Thu Feb 6 00:25:50 UTC 2025] 2025-02-06 00:25:50 +00:00
github-actions[bot]
4f4fd8786e Update: [Wed Feb 5 00:25:42 UTC 2025] 2025-02-05 00:25:42 +00:00
github-actions[bot]
71e69a3a26 Update: [Tue Feb 4 00:25:09 UTC 2025] 2025-02-04 00:25:09 +00:00
fab
339a5e0350
Update test_apache_docker.yml 2025-02-03 02:05:58 +01:00
fab
c3578e4570
Update test_nginx.yml 2025-02-03 02:05:25 +01:00
fab
132380eeaf
Update update_patterns.yml 2025-02-03 02:04:42 +01:00
fab
437d3a251c
Update update_patterns.yml 2025-02-03 02:02:52 +01:00
github-actions[bot]
4e0dfb87e1 Update: [Mon Feb 3 00:26:12 UTC 2025] 2025-02-03 00:26:12 +00:00
github-actions[bot]
b3d0e38516 Update: [Sun Feb 2 00:27:06 UTC 2025] 2025-02-02 00:27:06 +00:00
github-actions[bot]
16e5ffb42c Update: [Sat Feb 1 00:27:37 UTC 2025] 2025-02-01 00:27:37 +00:00
github-actions[bot]
4f409f223d Update: [Fri Jan 31 00:25:27 UTC 2025] 2025-01-31 00:25:27 +00:00
github-actions[bot]
c0a6dd804a Update: [Thu Jan 30 00:24:54 UTC 2025] 2025-01-30 00:24:54 +00:00
github-actions[bot]
b242ea0619 Update: [Wed Jan 29 00:25:14 UTC 2025] 2025-01-29 00:25:14 +00:00
fabriziosalmi
f1bae07d6c feat: Generate Nginx WAF config with separate map and rule files
This commit modifies the script to output two files:
- waf_maps.conf (for http block)
- waf_rules.conf (for server block)
to avoid conflicts and provide more flexibility.

This update should fix the bugged nginx rules integration on existing setups: https://github.com/fabriziosalmi/patterns/issues/8
2025-01-28 22:41:54 +01:00
github-actions[bot]
eaf5714520 Update: [Tue Jan 28 00:25:35 UTC 2025] 2025-01-28 00:25:35 +00:00
github-actions[bot]
0e59b87df0 Update: [Mon Jan 27 00:26:20 UTC 2025] 2025-01-27 00:26:20 +00:00