Skip to content

Add missing input validation to VERIFY_ACERT and VERIFY cert handler#317

Open
jackctj117 wants to merge 1 commit intomainfrom
Cert-VERIFY_ACERT-Handler
Open

Add missing input validation to VERIFY_ACERT and VERIFY cert handler#317
jackctj117 wants to merge 1 commit intomainfrom
Cert-VERIFY_ACERT-Handler

Conversation

@jackctj117
Copy link
Contributor

This pull request adds important input validation checks to the certificate verification request handlers in src/wh_server_cert.c. These changes improve the robustness and security of the server by ensuring that incoming requests are well-formed and do not cause buffer overflows or invalid memory accesses.

Input validation improvements:

  • Added a check to ensure the request size is at least as large as the expected request structure before processing verify ACERT requests, returning an error if not (WH_ERROR_ABORTED).
  • Added checks to both verify and verify ACERT request handlers to ensure the certificate data length does not exceed the remaining request size, returning an error (WH_ERROR_BADARGS) if the data would overflow. [1] [2]

Copilot AI review requested due to automatic review settings March 20, 2026 19:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds request-boundary validation to certificate verification handlers to prevent out-of-bounds reads and malformed request processing.

Changes:

  • Added bounds checks to ensure cert_len does not exceed remaining request payload for VERIFY and VERIFY_ACERT.
  • Added minimum request-size validation for VERIFY_ACERT before translating/parsing the request.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 515 to +526
wh_MessageCert_TranslateVerifyRequest(
magic, (whMessageCert_VerifyRequest*)req_packet, &req);

/* Validate certificate data fits within request */
if (req.cert_len > req_size - sizeof(req)) {
resp.rc = WH_ERROR_BADARGS;
wh_MessageCert_TranslateVerifyResponse(
magic, &resp,
(whMessageCert_VerifyResponse*)resp_packet);
*out_resp_size = sizeof(resp);
break;
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

In the VERIFY handler, the request is translated before any minimum-size check, which can allow an out-of-bounds read if req_size < sizeof(req). Additionally, req_size - sizeof(req) can underflow (if unsigned) and incorrectly bypass the bounds check. Add a minimum request-size validation (like the VERIFY_ACERT path) before wh_MessageCert_TranslateVerifyRequest(...), and only compute req_size - sizeof(req) after confirming req_size >= sizeof(req).

Copilot uses AI. Check for mistakes.
Comment on lines +519 to +526
if (req.cert_len > req_size - sizeof(req)) {
resp.rc = WH_ERROR_BADARGS;
wh_MessageCert_TranslateVerifyResponse(
magic, &resp,
(whMessageCert_VerifyResponse*)resp_packet);
*out_resp_size = sizeof(resp);
break;
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The newly added early-exit error handling repeats a multi-line pattern (set rc → translate response → set *out_resp_sizebreak) that now appears in multiple handlers. Consider extracting a small helper (or local utility macro) for formatting and emitting error responses to reduce duplication and make future validation additions less error-prone. This is optional, but would improve readability as validations expand.

Copilot uses AI. Check for mistakes.
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