266 Commits

Author SHA1 Message Date
Fabrizio Salmi
6bcca53eae Fix CI workflow and clarify Nginx WAF usage
- Remove redundant 'gh auth login' command in CI workflow (fixes exit code 1 error)
- Use GH_TOKEN env var instead of GITHUB_TOKEN for gh CLI
- Update Nginx README to clarify that individual category .conf files should not be included directly
- Document that users must use waf_maps.conf (http block) + waf_rules.conf (server block)

Fixes #17
2025-12-09 07:59:25 +01:00
fab
87f18886b7
Merge pull request #16 from fabriziosalmi/copilot/improve-documentation-quality
docs: Synchronize documentation with codebase and expand contribution guides
2025-11-15 20:46:44 +01:00
copilot-swe-agent[bot]
0e9d13cb5e docs: Add prerequisites, improve bug template, enhance security policy
Co-authored-by: fabriziosalmi <1569108+fabriziosalmi@users.noreply.github.com>
2025-11-15 19:35:18 +00:00
copilot-swe-agent[bot]
1fe6802ffe docs: Fix script names, improve CONTRIBUTING, add WAF READMEs, fix workflow
Co-authored-by: fabriziosalmi <1569108+fabriziosalmi@users.noreply.github.com>
2025-11-15 19:33:13 +00:00
copilot-swe-agent[bot]
908e93cf8c Initial plan 2025-11-15 19:28:04 +00:00
fab
ed0c2e736e
Update json2apache.py 2025-02-28 11:26:45 +01:00
fab
4c01d419de
Update update_patterns.yml
Explanation of the Workflow:

    Checkout: Checks out the repository. fetch-depth: 0 gets the full Git history, which is necessary for tag manipulation.

    Setup Python: Sets up Python 3.11.

    Cache: Caches the pip directory to speed up dependency installation.

    Install Dependencies: Installs dependencies from requirements.txt.

    Run Scripts: Runs the owasp2json.py, json2nginx.py, json2apache.py, json2traefik.py, and json2haproxy.py scripts to generate the WAF configurations. These steps will now fail fast if any of the scripts encounter an error.

    Generate Bad Bot Blockers: Executes badbots.py.

    Commit and Push (Conditional):

        Configures Git with a bot user.

        Adds all changes.

        Uses git diff --quiet --exit-code to check for changes. If there are no changes, the git diff command exits with a non-zero code, and the if condition is false.

        If there are changes, commits them with a descriptive message and pushes to the repository.

        continue-on-error: true is used only on this step because it's okay if there are no changes to commit.

    Create Zip Archives: Creates ZIP files containing the generated configurations for each web server. The (cd ... && zip ...) command ensures that the ZIP files contain the correct directory structure (e.g., nginx_waf.zip should contain a nginx/ directory).

    Delete Existing Release: Deletes the latest tag (both locally and remotely) and the latest release (if they exist). This ensures that we always have a clean "latest" release. Uses the gh CLI (GitHub CLI) for release management.

    Create GitHub Release (Conditional): The if: success() condition ensures that this step only runs if all preceding steps were successful. This prevents creating a new release if the rule generation failed. Creates a new release tagged as latest.

    Upload Assets (Conditional): Uploads the generated ZIP files as assets to the new release. Also uses if: success().

    Clean Up (Optional): Removes the pip cache. if: always() ensures this runs even if previous steps fail.

    Notify on Failure (Optional): Uses if: failure() to run only if a previous step failed. This step currently just prints a message, but you can replace it with a notification mechanism (e.g., sending a message to Slack or sending an email). You'll need to set up the necessary secrets (like SLACK_WEBHOOK) for your chosen notification method.
2025-02-28 11:25:24 +01:00
fab
23d11b6552
Update import_traefik_waf.py 2025-02-28 11:24:10 +01:00
fab
df23dd0d04
Update json2traefik.py 2025-02-28 11:23:08 +01:00
fab
8277d8bc13
Update import_nginx_waf.py 2025-02-28 11:22:21 +01:00
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