You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-commits@axis.apache.org by ro...@apache.org on 2026/09/20 21:03:44 UTC
(axis-axis2-c-core) 01/04: Make the URL operation authoritative on the Android static path
This is an automated email from the ASF dual-hosted git repository.
robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-c-core.git
commit 8a78396eb4568b26e10319589aa84d18da05108f
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Sun Sep 20 10:15:44 2026 -1000
Make the URL operation authoritative on the Android static path
A request body may name an operation ("action" or "operation"), and the
camera and audio services dispatch on it, but any authorization in front
of the server judged the URL, not the body. The engine now reconciles the
two: a body that names a different operation is refused unless the URL
resolved to a catch-all RESTLocation ("/" or none), where the body is the
only source by design. Same-operation and unnamed bodies are unchanged.
HTTP2_ANDROID.md documents the four cases.
Co-Authored-By: Claude Fable 5.1 <no...@anthropic.com>
---
docs/HTTP2_ANDROID.md | 26 ++++++++++-
src/core/receivers/axis2_json_rpc_msg_recv.c | 69 ++++++++++++++++++++++------
2 files changed, 80 insertions(+), 15 deletions(-)
diff --git a/docs/HTTP2_ANDROID.md b/docs/HTTP2_ANDROID.md
index 60dcb0263..1ed125701 100644
--- a/docs/HTTP2_ANDROID.md
+++ b/docs/HTTP2_ANDROID.md
@@ -381,14 +381,36 @@ Android services don't need these because:
the two-argument entry point, `try_android_static_service()` adds
`"operation": "<name>"` to the request object, where `<name>` is the operation
the URL path resolved to — the same name the four-argument server path reads
-from the message context. A request that already carries `"action"` or
-`"operation"` is left untouched. Route by that field first and infer from the
+from the message context. Route by that field first and infer from the
request's shape only as a fallback: two operations can share a field name (a
correlated `monteCarlo` request and a `portfolioVariance` request both carry
`"weights"`), and a shape rule that decided on `"weights"` alone sent the
first to the second. Neither `CameraControlService` nor `AudioSearchService`
reads `"operation"`, so the added field is inert for them.
+**Operation trust model (since 2026-09-20).** The URL is authoritative. Any
+authorization in front of the server — an httpd `<Location>` block, a
+module — has judged the URL, not the body, so a body that names a different
+operation must not be able to run it. The engine reconciles the two like
+this:
+
+| URL resolved to | Body names | Result |
+|---|---|---|
+| any operation | nothing | `"operation"` added; the service routes by it |
+| any operation | the same operation | invoked |
+| a catch-all location (`RESTLocation` of `/`, or none) | a different operation | invoked — a catch-all carries no operation, so the body is the only source, by design |
+| a specific location (`/startRecording`, `/monteCarlo`, …) | a different operation | **refused** with `status: FAILED` and an `error_message` naming both |
+
+The Kanaha camera and audio services both declare a catch-all operation
+(`jsonrpc` at `/`) whose clients name the operation with `"action"`, and one
+location per operation. Both keep working unchanged: the catch-all accepts
+body dispatch, and a per-operation URL with a matching `"action"` is the
+same-operation case. What changes is that `/startRecording` with
+`"action": "deleteFiles"` is now an error instead of a delete. This is what
+makes per-URL authorization in `httpd.conf` meaningful on the Android path;
+today the Kanaha configurations authorize the whole `/services` prefix
+behind mTLS, so nothing depended on the old behaviour.
+
Services that want to work in both environments can export both:
- `axis2_char_t* <serviceclass>_invoke_json(svc, env, json_str, msg_ctx)` for server-side
- `axis2_char_t* <serviceclass>_process_json_only(env, json_str)` for simpler contexts
diff --git a/src/core/receivers/axis2_json_rpc_msg_recv.c b/src/core/receivers/axis2_json_rpc_msg_recv.c
index 925259825..2310f6f33 100644
--- a/src/core/receivers/axis2_json_rpc_msg_recv.c
+++ b/src/core/receivers/axis2_json_rpc_msg_recv.c
@@ -39,6 +39,7 @@
#include <axutil_dll_desc.h>
#include <axutil_class_loader.h>
#include <axis2_http_header.h>
+#include <stdio.h>
#include <string.h>
#include <ctype.h> /* For character type functions */
#include <json-c/json.h>
@@ -172,6 +173,7 @@ axis2_bool_t
try_android_static_service(const axutil_env_t *env,
const char *service_name,
const char *operation_name,
+ axis2_bool_t body_names_operation,
const char *json_request_str,
axis2_char_t **json_response_out)
{
@@ -202,20 +204,48 @@ try_android_static_service(const axutil_env_t *env,
}
/*
- * Hand the service the operation the URL resolved to. The two-argument
- * entry point has no msg_ctx, so without this a statically linked service
- * can only guess the operation from the request's field names -- which
- * breaks as soon as two operations share a field (a correlated monteCarlo
- * request and a portfolioVariance request both carry "weights"). The
- * server-side path gets the same name from the message context; this
- * makes the Android path equivalent. A request that already names its
- * operation ("action" or "operation") is left alone.
+ * Operation trust model. The URL is authoritative: the operation it
+ * resolved to is what any authorization in front of this server (an
+ * httpd <Location>, a module) has already judged. The request body may
+ * also name an operation ("action" or "operation"), and services such as
+ * the camera and audio ones dispatch on it. Reconciling the two:
+ *
+ * - No name in the body: add "operation": "<url op>" so a statically
+ * linked service, which has no msg_ctx, does not have to guess the
+ * operation from field names (two operations can share a field).
+ * - The body names the same operation: fine.
+ * - The body names a different operation, and the URL is a catch-all
+ * location ("/" or none): allowed -- the catch-all carries no
+ * operation, so the body is the only source, by design.
+ * - The body names a different operation, and the URL is a specific
+ * location: refused. Honouring the body here would let a request to
+ * an authorized URL execute an operation the URL did not authorize.
*/
- if (operation_name && json_object_is_type(json_request, json_type_object) &&
- !json_object_object_get_ex(json_request, "action", NULL) &&
- !json_object_object_get_ex(json_request, "operation", NULL)) {
- json_object_object_add(json_request, "operation",
- json_object_new_string(operation_name));
+ if (operation_name && json_object_is_type(json_request, json_type_object)) {
+ json_object *named = NULL;
+ const char *body_op = NULL;
+ if (json_object_object_get_ex(json_request, "action", &named) ||
+ json_object_object_get_ex(json_request, "operation", &named)) {
+ body_op = json_object_get_string(named);
+ }
+ if (!body_op) {
+ json_object_object_add(json_request, "operation",
+ json_object_new_string(operation_name));
+ } else if (!body_names_operation && strcmp(body_op, operation_name) != 0) {
+ char msg[320];
+ snprintf(msg, sizeof(msg),
+ "{\"status\":\"FAILED\",\"error_message\":"
+ "\"operation mismatch: the URL names '%.64s' but the request body names '%.64s'. "
+ "Send the request to that operation's own path, or to the service root, "
+ "which dispatches on the body.\"}",
+ operation_name, body_op);
+ AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI,
+ "[ANDROID_STATIC] %s: refused body operation '%s' on URL operation '%s'",
+ service_name, body_op, operation_name);
+ json_object_put(json_request);
+ *json_response_out = axutil_strdup(env, msg);
+ return *json_response_out ? AXIS2_TRUE : AXIS2_FALSE;
+ }
}
/* Invoke service */
@@ -730,8 +760,21 @@ axis2_json_rpc_msg_recv_invoke_business_logic_sync(
"[JSON RPC MSG RECV] Android: Trying static service registry for '%s'",
service_name ? service_name : "unknown");
+ /* A catch-all REST location ("/" or none) carries no operation, so the
+ * body is allowed to name one there; anywhere else the URL wins. */
+ axis2_bool_t body_names_operation = AXIS2_FALSE;
+ if (op) {
+ axutil_param_t *loc_param = axis2_op_get_param(op, env, AXIS2_REST_HTTP_LOCATION);
+ const axis2_char_t *loc = loc_param
+ ? (const axis2_char_t *)axutil_param_get_value(loc_param, env) : NULL;
+ if (!loc || !*loc || (loc[0] == '/' && loc[1] == '\0')) {
+ body_names_operation = AXIS2_TRUE;
+ }
+ }
+
if (service_name && json_request &&
try_android_static_service(env, service_name, operation_name,
+ body_names_operation,
json_request, &json_response)) {
AXIS2_LOG_INFO(env->log,
"[JSON RPC MSG RECV] Android: Static service '%s' invoked successfully",