-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update SQLi/XSS operators for libinjection v4.0.0 cleaned #3528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Easton97-Jens
wants to merge
23
commits into
owasp-modsecurity:v3/master
Choose a base branch
from
Easton97-Jens:v3/master-libinjection-v4.0-final
base: v3/master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
58fc3da
Update libinjection to v4.0.0
e1a527e
Make detect_sqli and detect_xss compatible with libinjection v4
d2cef41
Update regression tests for libinjection v4 compatibility
9e66822
syntax adjustment
633f2eb
Add capture/non-capture regression coverage for detectSQLi/XSS
Easton97-Jens b264dbf
Merge pull request #27 from Easton97-Jens/codex/add-regression-tests-…
Easton97-Jens 7cd1d67
Fix Windows test include path and case-insensitive override matching
Easton97-Jens 2aed15b
Merge pull request #31 from Easton97-Jens/codex/add-regression-tests-…
Easton97-Jens 0af7e13
Update libinjection_adapter.cc
Easton97-Jens d8c7395
Merge branch 'owasp-modsecurity:v3/master' into v3/master-libinjectio…
Easton97-Jens d6648d1
Add libinjection_error.h to Makefile.am
Easton97-Jens 19ea6d0
Isolate transaction state in multithreaded unit tests
Easton97-Jens e152a09
Merge pull request #32 from Easton97-Jens/codex/review-multithreaded-…
Easton97-Jens 719d172
Merge branch 'v3/master' into v3/master-libinjection-v4.0-final
Easton97-Jens 468f681
Update libinjection_adapter.cc
Easton97-Jens d19f58b
Update libinjection_adapter.h
Easton97-Jens 91fbf35
Hide testing override functions from symbol table
Easton97-Jens e10e9e0
Log input in hex format for SQLi detection
Easton97-Jens 29a461b
Add logging for input in XSS detection
Easton97-Jens 7c104e4
Update multithreaded unit test implementation
Easton97-Jens 0cf4f3c
Update libinjection_adapter.h
Easton97-Jens 3e98c81
Guard log-only detect operator variables under NO_LOGS
Easton97-Jens e500702
Merge pull request #42 from Easton97-Jens/codex/fix-cppcheck-unreadva…
Easton97-Jens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule libinjection
updated
155 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * ModSecurity, http://www.modsecurity.org/ | ||
| * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/) | ||
| * | ||
| * You may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * If any of the files related to licensing are missing or if you have any | ||
| * other questions related to licensing please contact Trustwave Holdings, Inc. | ||
| * directly using the email address security@modsecurity.org. | ||
| * | ||
| */ | ||
|
|
||
| #include "src/operators/libinjection_adapter.h" | ||
|
|
||
| #include "libinjection/src/libinjection.h" | ||
|
|
||
| namespace modsecurity::operators { | ||
| namespace { | ||
|
|
||
| // Per-thread overrides avoid cross-thread interference during mtstress tests. | ||
| // Intentional design: | ||
| // - thread_local to isolate tests across threads | ||
| // - function pointers to keep zero-overhead call path | ||
| // - mutable for test injection hooks | ||
| // NOSONAR: required for testing override mechanism (see set*OverrideForTesting) | ||
| thread_local DetectSQLiFn g_sqli_override = nullptr; // NOSONAR | ||
| thread_local DetectXSSFn g_xss_override = nullptr; // NOSONAR | ||
|
|
||
| } | ||
|
|
||
| injection_result_t runLibinjectionSQLi(const char *input, size_t len, | ||
| char *fingerprint) { | ||
| if (DetectSQLiFn fn = g_sqli_override) { | ||
| return fn(input, len, fingerprint); | ||
| } | ||
|
|
||
| return libinjection_sqli(input, len, fingerprint); | ||
| } | ||
|
|
||
| injection_result_t runLibinjectionXSS(const char *input, size_t len) { | ||
| if (DetectXSSFn fn = g_xss_override) { | ||
| return fn(input, len); | ||
| } | ||
|
|
||
| return libinjection_xss(input, len); | ||
| } | ||
|
|
||
| // Test-only hook: allows injecting alternative detection functions | ||
| // NOSONAR: function pointer is intentional (no std::function overhead) | ||
| void setLibinjectionSQLiOverrideForTesting(DetectSQLiFn fn) { // NOSONAR | ||
| g_sqli_override = fn; | ||
| } | ||
|
|
||
| // Test-only hook: allows injecting alternative detection functions | ||
| // NOSONAR: function pointer is intentional (no std::function overhead) | ||
| void setLibinjectionXSSOverrideForTesting(DetectXSSFn fn) { // NOSONAR | ||
| g_xss_override = fn; | ||
| } | ||
|
|
||
| void clearLibinjectionOverridesForTesting() { | ||
| g_sqli_override = nullptr; | ||
| g_xss_override = nullptr; | ||
| } | ||
|
|
||
| } // namespace modsecurity::operators | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * ModSecurity, http://www.modsecurity.org/ | ||
Easton97-Jens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/) | ||
| * | ||
| * You may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * If any of the files related to licensing are missing or if you have any | ||
| * other questions related to licensing please contact Trustwave Holdings, Inc. | ||
| * directly using the email address security@modsecurity.org. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef SRC_OPERATORS_LIBINJECTION_ADAPTER_H_ | ||
| #define SRC_OPERATORS_LIBINJECTION_ADAPTER_H_ | ||
|
|
||
| #include <cstddef> | ||
|
|
||
| #include "libinjection/src/libinjection_error.h" // matches detect_xss.cc, detect_sqli.cc, and libinjection_utils.h | ||
|
|
||
| namespace modsecurity::operators { | ||
|
|
||
| using DetectSQLiFn = injection_result_t (*)(const char *, size_t, char *); | ||
| using DetectXSSFn = injection_result_t (*)(const char *, size_t); | ||
|
|
||
| injection_result_t runLibinjectionSQLi(const char *input, size_t len, | ||
| char *fingerprint); | ||
| injection_result_t runLibinjectionXSS(const char *input, size_t len); | ||
|
|
||
| void setLibinjectionSQLiOverrideForTesting(DetectSQLiFn fn); | ||
| void setLibinjectionXSSOverrideForTesting(DetectXSSFn fn); | ||
| void clearLibinjectionOverridesForTesting(); | ||
|
|
||
| } // namespace modsecurity::operators | ||
|
|
||
| #endif // SRC_OPERATORS_LIBINJECTION_ADAPTER_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * ModSecurity, http://www.modsecurity.org/ | ||
| * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/) | ||
| * | ||
| * You may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * If any of the files related to licensing are missing or if you have any | ||
| * other questions related to licensing please contact Trustwave Holdings, Inc. | ||
| * directly using the email address security@modsecurity.org. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef SRC_OPERATORS_LIBINJECTION_UTILS_H_ | ||
| #define SRC_OPERATORS_LIBINJECTION_UTILS_H_ | ||
|
|
||
| #include "libinjection/src/libinjection_error.h" | ||
|
|
||
| namespace modsecurity::operators { | ||
|
|
||
| /* | ||
| * libinjection parser errors are handled in fail-safe mode as suspicious | ||
| * results, so callers can block on both confirmed detections and parser | ||
| * failures. | ||
| */ | ||
| static inline bool isMaliciousLibinjectionResult(injection_result_t result) { | ||
| return result == LIBINJECTION_RESULT_TRUE | ||
| || result == LIBINJECTION_RESULT_ERROR; | ||
| } | ||
|
|
||
| static inline const char *libinjectionResultToString(injection_result_t result) { | ||
| switch (result) { | ||
| case LIBINJECTION_RESULT_TRUE: | ||
| return "attack-detected"; | ||
| case LIBINJECTION_RESULT_FALSE: | ||
| return "no-attack"; | ||
| case LIBINJECTION_RESULT_ERROR: | ||
| return "parser-error"; | ||
| } | ||
|
|
||
| return "unexpected-result"; | ||
| } | ||
|
|
||
| } // namespace modsecurity::operators | ||
|
|
||
| #endif // SRC_OPERATORS_LIBINJECTION_UTILS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.