paivana

HTTP paywall reverse proxy
Log | Files | Refs | Submodules | README | LICENSE

commit 030ce29b4b14db3f57439909a8be650304bd539d
parent 5afb0c93618785c6b0fed4cb8f5130f854f0dd2a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 31 May 2026 01:30:53 +0200

-more bugfixes

Diffstat:
Msrc/backend/paivana-httpd_cookie.c | 2+-
Msrc/backend/paivana-httpd_helper.c | 32+++++++++++++++++---------------
Msrc/backend/paivana-httpd_pay.c | 5+++++
Msrc/backend/paivana-httpd_reverse.c | 17++++++++---------
Msrc/backend/paivana-httpd_templates.c | 21+++++++++++++++------
5 files changed, 46 insertions(+), 31 deletions(-)

diff --git a/src/backend/paivana-httpd_cookie.c b/src/backend/paivana-httpd_cookie.c @@ -183,7 +183,7 @@ PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp cur_time, *end = '\0'; GNUNET_asprintf ( &res, - "Paivana-Cookie=%llu-%s; %sPath=%s; Max-Age=%llu;", + "Paivana-Cookie=%llu-%s; %sPath=%s; Max-Age=%llu; HttpOnly;", (unsigned long long) (cur_time.abs_time.abs_value_us / 1000LLU / 1000LLU), cstr, use_https diff --git a/src/backend/paivana-httpd_helper.c b/src/backend/paivana-httpd_helper.c @@ -111,9 +111,7 @@ bool PAIVANA_HTTPD_get_base_url (struct MHD_Connection *connection, struct GNUNET_Buffer *buf) { - const char *host; const char *forwarded_host; - const char *forwarded_port; GNUNET_buffer_clear (buf); if (NULL != PH_base_url) @@ -129,19 +127,33 @@ PAIVANA_HTTPD_get_base_url (struct MHD_Connection *connection, else GNUNET_buffer_write_str (buf, "http://"); - host = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, - MHD_HTTP_HEADER_HOST); forwarded_host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "X-Forwarded-Host"); if (NULL != forwarded_host) { + const char *forwarded_port; + GNUNET_buffer_write_str (buf, forwarded_host); + forwarded_port = MHD_lookup_connection_value (connection, + MHD_HEADER_KIND, + "X-Forwarded-Port"); + if (NULL != forwarded_port) + { + GNUNET_buffer_write_str (buf, + ":"); + GNUNET_buffer_write_str (buf, + forwarded_port); + } } else { + const char *host; + + host = MHD_lookup_connection_value (connection, + MHD_HEADER_KIND, + MHD_HTTP_HEADER_HOST); if (NULL == host) { GNUNET_break (0); @@ -150,15 +162,5 @@ PAIVANA_HTTPD_get_base_url (struct MHD_Connection *connection, GNUNET_buffer_write_str (buf, host); } - forwarded_port = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, - "X-Forwarded-Port"); - if (NULL != forwarded_port) - { - GNUNET_buffer_write_str (buf, - ":"); - GNUNET_buffer_write_str (buf, - forwarded_port); - } return true; } diff --git a/src/backend/paivana-httpd_pay.c b/src/backend/paivana-httpd_pay.c @@ -123,6 +123,11 @@ PAIVANA_HTTPD_payment_shutdown () { struct PayRequest *ph = ph_head; + if (NULL != ph->co) + { + TALER_MERCHANT_get_private_order_cancel (ph->co); + ph->co = NULL; + } GNUNET_CONTAINER_DLL_remove (ph_head, ph_tail, ph); diff --git a/src/backend/paivana-httpd_reverse.c b/src/backend/paivana-httpd_reverse.c @@ -185,11 +185,6 @@ struct HttpRequest struct GNUNET_SCHEDULER_Task *wtask; /** - * Hold the response obtained by modifying the original one. - */ - struct MHD_Response *mod_response; - - /** * MHD response object for this request. */ struct MHD_Response *response; @@ -611,7 +606,7 @@ curl_check_hdr (void *buffer, GNUNET_free (ndup); return bytes; } - if (' ' == *hdr_val) + while (' ' == *hdr_val) hdr_val++; /* MHD does not allow certain characters in values, @@ -847,6 +842,8 @@ con_val_iter (void *cls, char *hdr; (void) kind; + if (NULL == value) + return MHD_YES; if (0 == strcasecmp (MHD_HTTP_HEADER_HOST, key)) { @@ -1041,7 +1038,8 @@ buffer_upload_chunk (struct HttpRequest *hr, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing %u bytes UPLOAD\n", (unsigned int) upload_data_size); - if (hr->io_len + upload_data_size > PH_request_buffer_max) + if ( (hr->io_len + upload_data_size > PH_request_buffer_max) || + (hr->io_len + upload_data_size > UINT_MAX) ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Upload exceeds %llu byte limit, rejecting\n", @@ -1054,8 +1052,9 @@ buffer_upload_chunk (struct HttpRequest *hr, GNUNET_assert (upload_data_size + hr->io_len > hr->io_len); GNUNET_array_grow (hr->io_buf, hr->io_size, - GNUNET_MAX - (hr->io_size * 2 + 1024, + GNUNET_MAX ( + GNUNET_MIN (hr->io_size * 2 + 1024, + UINT_MAX), upload_data_size + hr->io_len)); } GNUNET_memcpy (&hr->io_buf[hr->io_len], diff --git a/src/backend/paivana-httpd_templates.c b/src/backend/paivana-httpd_templates.c @@ -292,7 +292,7 @@ load_paywall (struct MHD_Connection *conn, "has_choices", 1 < json_array_size (t->choices)), GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_object_steal ( + GNUNET_JSON_pack_object_incref ( "default_choice", json_array_get (t->choices, 0))), GNUNET_JSON_pack_uint64 ( @@ -374,8 +374,9 @@ load_paywall (struct MHD_Connection *conn, * * @param[in,out] t template to update * @param contract contract to parse + * @return true on success, false on failure */ -static void +static bool parse_template (struct Template *t, const json_t *contract) { @@ -411,7 +412,7 @@ parse_template (struct Template *t, "Invalid template %s at field %s\n", t->template_id, en); - return; + return false; } if (NULL != regex) { @@ -424,7 +425,7 @@ parse_template (struct Template *t, "Invalid regex in template %s: %s\n", t->template_id, regex); - return; + return false; } t->regex = GNUNET_strdup (regex); } @@ -435,6 +436,7 @@ parse_template (struct Template *t, "Using payment template %s for `%s'\n", t->template_id, regex); + return true; } @@ -453,8 +455,15 @@ setup_template ( switch (tgr->hr.http_status) { case MHD_HTTP_OK: - parse_template (t, - tgr->details.ok.template_contract); + if (! parse_template (t, + tgr->details.ok.template_contract)) + { + GNUNET_free (t->template_id); + GNUNET_CONTAINER_DLL_remove (t_head, + t_tail, + t); + GNUNET_free (t); + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_ERROR,