Skip to content

Commit

Permalink
dpop.c: support remote ip detection on older Apache versions
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Zandbelt <[email protected]>
  • Loading branch information
zandbelt committed Jun 12, 2024
1 parent c5ef5fd commit 1ca9658
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/handle/dpop.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include "proto/proto.h"
#include "util.h"

#include <ap_mmn.h>

#define OIDC_DPOP_PARAM_URL "url"
#define OIDC_DPOP_PARAM_NONCE "nonce"
#define OIDC_DPOP_PARAM_METHOD "method"
Expand All @@ -58,22 +60,28 @@ int oidc_dpop_request(request_rec *r, oidc_cfg_t *c) {
char *s_dpop = NULL;
char *s_response = NULL;
json_t *json = NULL;
char *remote_ip = NULL;

#if AP_MODULE_MAGIC_AT_LEAST(20111130, 0)
remote_ip = r->useragent_ip;
#else
remote_ip = r->connection->remote_ip;
#endif

if (apr_hash_get(oidc_cfg_info_hook_data_get(c), OIDC_HOOK_INFO_DPOP, APR_HASH_KEY_STRING) == NULL) {
oidc_error(r, "DPoP hook called but \"dpop\" is not enabled in %s", OIDCInfoHook);
goto end;
}

/* try to make sure that the proof-of-possession semantics are preserved */
if ((_oidc_strnatcasecmp(r->useragent_ip, r->connection->local_ip) != 0) &&
if ((_oidc_strnatcasecmp(remote_ip, r->connection->local_ip) != 0) &&
(apr_table_get(r->subprocess_env, "OIDC_DPOP_API_INSECURE") == 0)) {
oidc_warn(
r,
"reject DPoP creation request from remote host: you should create a separate virtual (sub)host "
"that requires client certificate authentication to allow and proxy this request "
"(r->useragent_ip=%s, "
"that requires client certificate authentication to allow and proxy this request (remote_ip=%s, "
"r->connection->local_ip=%s)",
r->useragent_ip, r->connection->local_ip);
remote_ip, r->connection->local_ip);
rc = HTTP_UNAUTHORIZED;
goto end;
}
Expand Down

0 comments on commit 1ca9658

Please sign in to comment.