[tmf] validate method as POST centrally in resource handlers (#12661)

This commit updates the central CoAP resource handlers in TMF agents
(`Agent::HandleResource`, `BackboneTmfAgent::HandleResource`, and
`Manager::CoapDtlsSession::HandleResource`) to verify that the
incoming request method is a POST request. If the URI is recognized
but the method is not POST, a `kCodeMethodNotAllowed` response is
now sent.

Since all TMF requests are now guaranteed to be POST requests before
reaching their specific handlers, the `IsPostRequest()` checks in
individual handlers are removed. Additionally, the
`IsConfirmablePostRequest()` and `IsNonConfirmablePostRequest()`
helper methods in `Coap::Message` are removed and their usages are
simplified to `IsConfirmable()` and `IsNonConfirmable()` in the
respective handlers.
This commit is contained in:
Abtin Keshavarzian
2026-03-10 22:07:43 -05:00
committed by GitHub
parent d9fce062c7
commit 3559cbd55a
21 changed files with 44 additions and 63 deletions
+7
View File
@@ -72,6 +72,12 @@ bool Agent::HandleResource(const char *aUriPath, Msg &aMsg)
bool didHandle = true;
Uri uri = UriFromPath(aUriPath);
if ((uri != kUriUnknown) && !aMsg.IsPostRequest())
{
IgnoreError(SendAckResponse(aMsg, ot::Coap::kCodeMethodNotAllowed));
ExitNow();
}
#define Case(kUri, Type) \
case kUri: \
Get<Type>().HandleTmf<kUri>(aMsg); \
@@ -159,6 +165,7 @@ bool Agent::HandleResource(const char *aUriPath, Msg &aMsg)
#undef Case
exit:
return didHandle;
}