Skip to content

Enhance rsa robustness - #853

Open
xuzhenbao wants to merge 4 commits into
apache:masterfrom
xuzhenbao:enhance_rsa_robustness
Open

xuzhenbao wants to merge 4 commits into
apache:masterfrom
xuzhenbao:enhance_rsa_robustness

Conversation

@xuzhenbao

Copy link
Copy Markdown
Contributor

Harden the remote service admin request handling against malformed input. This PR fixes a
heap buffer overflow in the RSA DFI HTTP server and in the discovery endpoint descriptor
parser, and adds validation of shared memory message ranges in the RSA SHM v2 server.

@PengZheng
PengZheng requested a review from pnoltes November 10, 2026 01:51

@pnoltes pnoltes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice robustness changes. I think the rsa dfi mg_read usage needs some improvement.


/**
* @brief Remote Service Admin DFI environment property (named "CELIX_RSA_DFI_MAX_REQUEST_SIZE") which specifies
* the maximum accepted HTTP request body size in bytes. Requests with a larger body are rejected with a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be configurable in bytes? I would expect al uses cases want as mac request size at least 1 MB.

I think it would be better to rename this to CELIX_RSA_DFI_MAX_REQUEST_SIZE_IN_MB and set the default to 16.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or CELIX_RSA_DFI_MAX_REQUEST_SIZE_IN_KB so that it can be adjusted for resource-constrained environment?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , IN_KB will also work for me


if (contentLength < 0 || (uint64_t)contentLength > rsa->maxRequestSize) {
RSA_LOG_WARNING(rsa, "Rejecting request with invalid or too large body (content length %lld, max %zu)", (long long)contentLength, rsa->maxRequestSize);
mg_write(conn, request_too_large_response_headers, strlen(request_too_large_response_headers));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mg_write(conn, request_too_large_response_headers, strlen(request_too_large_response_headers));
mg_send_http_error(conn, 413, "%s", "Rejecting request with invalid or too large body (content length %lld)", (long long)contentLength);

I would not respond with the configured max request size.

The same setup can be use for the 500 error.

RSA_LOG_ERROR(rsa, "Error allocating memory for request body of %zu bytes", (size_t)contentLength);
mg_write(conn, internal_error_response_headers, strlen(internal_error_response_headers));
} else {
int nrOfBytesRead = mg_read(conn, data, (size_t)contentLength);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note there is overlap in the change with: #851
My proposal is to focus on this PR and I will update #851 after this is merged.

the usage of mg_read should be in a while loop, according to the [documentation])https://github.com/civetweb/civetweb/blob/master/docs/api/mg_read.md), mg_read will return a negative value when there is nothing more the read.

@xuzhenbao
xuzhenbao requested a review from pnoltes November 23, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants