Commit Graph

1185 Commits

Author SHA1 Message Date
Nicolás A. Ortega Froysa
53367b22a8 Bump version to v0.9.5
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-06-09 10:41:13 +02:00
Nicolás A. Ortega Froysa
09fe3ed5de http: Fix PARM parsing
Also add a test.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-06-06 14:25:35 +02:00
Nicolás A. Ortega Froysa
13750e2f5a tests: curl URL between quotation marks
Put the curl URL between quotation marks to make sure to include URLs that
contains strange characters such as ';'.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-06-06 14:25:05 +02:00
Nicolás A. Ortega Froysa
29ae631a76 state: remove unnecessary zcu time update
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-31 09:45:03 +02:00
Nicolás A. Ortega Froysa
9d71332b74 Move ERR_BUF_MAX_SIZE to proper header.
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-31 08:59:31 +02:00
Nicolás A. Ortega Froysa
382b9ac0a8 ctl: remove use of std::string
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-31 08:25:04 +02:00
Nicolás A. Ortega Froysa
5c0cc48825 counter: remove dead code
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-30 12:22:40 +02:00
Nicolás A. Ortega Froysa
0fb826fb76 json: refactor std::vector to list_head
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-29 14:45:03 +02:00
Nicolás A. Ortega Froysa
d2ba5edb99 session: remove defunct
Remove the defunct variable from zproxy_session_node, and simply use refcnt.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-29 11:47:00 +02:00
Nicolás A. Ortega Froysa
009d478d63 state: use C atomic_int instead of std::atomic class
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-26 15:45:10 +02:00
Nicolás A. Ortega Froysa
64641b9c8e Undo commit de2298e5
For whatever reason, this commit was causing an issue with reloads and empty
services. So we should leave this bit alone.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-26 14:57:08 +02:00
Nicolás A. Ortega Froysa
20ee0a7700 docs: mark BODY variable as not required for ctl command
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-26 09:10:49 +02:00
Nicolás A. Ortega Froysa
f446a19340 state: use signed integer for sessions counter
Because the counter is reduced by the size of a sessions struct, which may be
larger than the remaining count, thus causing a negative number. If using an
unsigned long integer then the counter would simply loop back.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-25 16:53:18 +02:00
Nicolás A. Ortega Froysa
85c25252b4 state: don't unlock in state lookup
The mutex should only be unlocked (from the lookup lock) by the state release
function.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-25 16:46:19 +02:00
Nicolás A. Ortega Froysa
144c88d180 tests: add test for listener removal
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-25 16:02:02 +02:00
Nicolás A. Ortega Froysa
81351bb97c state: remove unordered_map usage
Replacing unordered_map usage with list_head. This also includes the switch from
shared_ptr to a raw C pointer.

Yes, I moved around a lot of the functions, particularly in the header file, but
it was a mess and I was having difficulty keeping track of function
declarations. Please pardon the noise.

The refcnt variable was removed from zproxy_backend_state and
zproxy_service_state, since they should only ever be used directly in state.cpp.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-25 14:41:47 +02:00
Nicolás A. Ortega Froysa
60afe68f7b Change syslog() to zcu_log_print()
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-25 08:29:21 +02:00
Nicolás A. Ortega Froysa
0ff75de79f waf: use streamLogWaf() for WAF logs
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-24 14:25:12 +02:00
Nicolás A. Ortega Froysa
1e978fef4f tests: add extra tests to ctl_responses
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-24 12:52:51 +02:00
Nicolás A. Ortega Froysa
1eeb95a335 tests: test culling of sessions with removed backend
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-24 12:34:07 +02:00
Nicolás A. Ortega Froysa
1fee450516 ctl: add 404 safe-guards for service sessions stats
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-24 12:29:41 +02:00
Nicolás A. Ortega Froysa
76b2046b4e session: add more information to session dump
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-24 09:58:09 +02:00
Nicolás A. Ortega Froysa
6baeb639c0 session: maintain lock through entire session add function
zproxy_session_add() has 4 steps: 1) check if session exists, 2) create new
session, 3) add session to the sessions list, 4) return the session. In the
previous procedure there were mutex locks around step 1 and step 3. This meant
that while one process was on step 2 creating a session, another process could
be in step 1 checking to see if it already exists, and then later creating the
same session. This race condition has been resolved by putting a mutex lock
around steps 1-3, and only releasing the mutex right before returning the
session in step 4.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-24 09:47:17 +02:00
Nicolás A. Ortega Froysa
2b17ba5b83 tests: add CTL stats call to stress_sess_ip_reload
This should help for debugging some of the oddities in this test.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-23 10:35:53 +02:00
Nicolás A. Ortega Froysa
a4bb1c8410 state: remove unnecessary constructor
zproxy_service_state doesn't require a constructor anymore.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-23 09:48:44 +02:00
Nicolás A. Ortega Froysa
584a085cfa Change C++ string parameters to C string.
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-23 09:01:08 +02:00
Nicolás A. Ortega Froysa
ec77f70c79 tests: normalize stress_sess_ip_reload
The test was somewhat unpredictable due to the configuration of zproxy_new.cfg.
This should make the test a little more predictable, and therefore not give a
false negative (falsely failing the test).

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-23 08:40:26 +02:00
Nicolás A. Ortega Froysa
6eaf067178 state: fix session memory leak on service unification
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-22 14:46:24 +02:00
Nicolás A. Ortega Froysa
3f328c70e7 tests: add a test for service unification
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-22 13:33:02 +02:00
Nicolás A. Ortega Froysa
dc2ba24558 session: safe delete sessions
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-19 10:24:06 +02:00
Nicolás A. Ortega Froysa
48a2093e1d tests: ignore binary file matches
Ignore this message from grep so we can keep the test output clean.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-19 09:11:08 +02:00
Nicolás A. Ortega Froysa
d1b41fef41 session: remove double-unlock for mutex
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-18 13:37:41 +02:00
Nicolás A. Ortega Froysa
23e5b645ae config: Remove use of std::string from config
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-18 11:49:10 +02:00
Nicolás A. Ortega Froysa
04259d85de session: remove unneeded jansson include
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-18 10:26:18 +02:00
Nicolás A. Ortega Froysa
52b2c4cfc3 state: use proper include format for system header
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-18 09:36:04 +02:00
Nicolás A. Ortega Froysa
7f217d02ac main: don't free cfg twice
/root/zproxy/src/main.c: In function ‘int zproxy_cfg_file_reload()’:
/root/zproxy/src/main.c:155:21: warning: pointer ‘cfg’ used after ‘void free(void*)’ [-Wuse-after-free]
  155 |                 free(cfg);
      |                 ~~~~^~~~~
In function ‘int zproxy_cfg_reload(zproxy_cfg*)’,
    inlined from ‘int zproxy_cfg_reload(zproxy_cfg*)’ at /root/zproxy/src/main.c:117:5,
    inlined from ‘int zproxy_cfg_file_reload()’ at /root/zproxy/src/main.c:154:23:
/root/zproxy/src/main.c:126:21: note: call to ‘void free(void*)’ here
  126 |                 free(cfg);
      |                 ~~~~^~~~~

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-18 09:31:39 +02:00
Nicolás A. Ortega Froysa
a876bb9e61 http: add include for iterator
/root/zproxy/src/http_manager.cpp:215:30: error: ‘istream_iterator’ is not a member of ‘std’
  215 |                         std::istream_iterator<std::string> begin(
      |                              ^~~~~~~~~~~~~~~~
/root/zproxy/src/http_manager.cpp:29:1: note: ‘std::istream_iterator’ is defined in header ‘<iterator>’; did you forget to ‘#include <iterator>’?
   28 | #include "session.h"
  +++ |+#include <iterator>
   29 |

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-18 09:26:36 +02:00
Nicolás A. Ortega Froysa
44b9034cf2 config: disallow broadcast address backends
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-17 13:00:30 +02:00
Nicolás A. Ortega Froysa
f9e4afc6c5 config: consolidate Err(WAF) code.
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-17 08:38:26 +02:00
Nicolás A. Ortega Froysa
8bcadca732 config: also print parse errors in syslog
These should be printed in syslog in the cases of parse errors during reloads,
in which there is no available stderr and stdout available.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-17 08:30:36 +02:00
Nicolás A. Ortega Froysa
27fed368a4 config: allow formatting in parse_error() macro
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-16 16:49:08 +02:00
Nicolás A. Ortega Froysa
b7c6243ae2 Remove unnecessary dirstamp files.
Probably leftovers from a previous build system.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-16 15:39:04 +02:00
Nicolás A. Ortega Froysa
7e81675320 tests: fix test request_body_without_delimiter
This test keeps failing for no reason. The difference is insignificant and
shouldn't affect anything.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-16 14:21:44 +02:00
Nicolás A. Ortega Froysa
43e334196b config: unite all Err directives
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-16 13:16:01 +02:00
Nicolás A. Ortega Froysa
31b29ba7dc config: add code specification to ErrWAF directive
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-16 12:21:19 +02:00
Nicolás A. Ortega Froysa
46415f795a tests: add waf_change_rules
Test for adding/removing WAF rules in a reload.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-15 09:02:41 +02:00
Nicolás A. Ortega Froysa
334ebef072 tests: Enable XSS WAF tests
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-12 13:41:59 +02:00
Nicolás A. Ortega Froysa
0cb924daa8 config: allow for multiple WAFRules directives
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-12 13:34:36 +02:00
Nicolás A. Ortega Froysa
790167fa1e config: Actually print WAF Rules
It wouldn't print the rules because they hadn't been loaded yet. This is a
remained from when the rules were loaded directly during the process of reading
the config file.

Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-12 10:47:17 +02:00
Nicolás A. Ortega Froysa
50ebfb3528 log: Change loglevel of streamLogError()
Signed-off-by: Nicolás A. Ortega Froysa <nicolas.ortega@zevenet.com>
2023-05-11 16:16:42 +02:00