Skip to content

Commit fe64efa

Browse files
committed
id_token: add "off" option to OIDCPassIDTokenAs
so no claims from the ID token will be passed on Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 5044966 commit fe64efa

File tree

6 files changed

+49
-45
lines changed

6 files changed

+49
-45
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
11/18/2025
2+
- id_token: add "off" option to OIDCPassIDTokenAs so no claims from the ID token will be passed on
3+
14
11/17/2025
25
- metadata: avoid double-free when validation of provider metadata fails
36
- perf: store id_token/userinfo claims as JSON objects and avoid parsing/serializing overhead

auth_openidc.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,11 @@
849849
# "claims" : the claims in the id_token are passed in individual headers/environment variables
850850
# "payload" : the payload of the id_token is passed as a JSON object in the "OIDC_id_token_payload" header/environment variable
851851
# "serialized" : the complete id_token is passed in compact serialized format in the "OIDC_id_token" header/environment variable
852+
# "off" : no id_token information is passed (overrides other options)
852853
# Note that when OIDCSessionType client-cookie is set, the id_token itself is not stored in the session/cookie (unless explicitly
853854
# configured to do so) and as such the header for the "serialized" option will not be set.
854855
# Can be configured on a per Directory/Location basis. When not defined the default "claims" is used..
855-
#OIDCPassIDTokenAs [claims|payload|serialized]+
856+
#OIDCPassIDTokenAs [claims|payload|serialized|off]+
856857

857858
# Define the way(s) in which the claims resolved from the userinfo endpoint are passed to the application according to OIDCPassClaimsAs.
858859
# Must be one or several of:

src/cfg/cmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ const command_rec oidc_cfg_cmds[] = {
781781
pass_refresh_token,
782782
"Pass the refresh token in a header and/or environment variable (On or Off)"),
783783
OIDC_CFG_CMD_DIR(
784-
AP_INIT_TAKE123,
784+
AP_INIT_ITERATE,
785785
OIDCPassIDTokenAs,
786786
pass_idtoken_as,
787787
"Set the format in which the id_token is passed in (a) header(s); must be one or more of: claims | payload | serialized"),

src/cfg/dir.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ struct oidc_dir_cfg_t {
8181
#define OIDC_PASS_ID_TOKEN_AS_CLAIMS_STR "claims"
8282
#define OIDC_PASS_IDTOKEN_AS_PAYLOAD_STR "payload"
8383
#define OIDC_PASS_IDTOKEN_AS_SERIALIZED_STR "serialized"
84+
#define OIDC_PASS_IDTOKEN_OFF_STR "off"
8485

8586
/*
8687
* define how to pass the id_token/claims in HTTP headers
8788
*/
88-
const char *oidc_cmd_dir_pass_idtoken_as_set(cmd_parms *cmd, void *m, const char *v1, const char *v2, const char *v3) {
89+
const char *oidc_cmd_dir_pass_idtoken_as_set(cmd_parms *cmd, void *m, const char *arg) {
8990
oidc_dir_cfg_t *dir_cfg = (oidc_dir_cfg_t *)m;
9091

9192
oidc_pass_idtoken_as_t type;
@@ -94,28 +95,18 @@ const char *oidc_cmd_dir_pass_idtoken_as_set(cmd_parms *cmd, void *m, const char
9495
static const oidc_cfg_option_t options[] = {
9596
{OIDC_PASS_IDTOKEN_AS_CLAIMS, OIDC_PASS_ID_TOKEN_AS_CLAIMS_STR},
9697
{OIDC_PASS_IDTOKEN_AS_PAYLOAD, OIDC_PASS_IDTOKEN_AS_PAYLOAD_STR},
97-
{OIDC_PASS_IDTOKEN_AS_SERIALIZED, OIDC_PASS_IDTOKEN_AS_SERIALIZED_STR}};
98+
{OIDC_PASS_IDTOKEN_AS_SERIALIZED, OIDC_PASS_IDTOKEN_AS_SERIALIZED_STR},
99+
{OIDC_PASS_IDTOKEN_OFF, OIDC_PASS_IDTOKEN_OFF_STR}};
98100

99-
if (v1) {
100-
rv = oidc_cfg_parse_option(cmd->pool, options, OIDC_CFG_OPTIONS_SIZE(options), v1, (int *)&type);
101+
if (arg) {
102+
rv = oidc_cfg_parse_option(cmd->pool, options, OIDC_CFG_OPTIONS_SIZE(options), arg, (int *)&type);
101103
if (rv != NULL)
102104
return OIDC_CONFIG_DIR_RV(cmd, rv);
103105
// NB: assign the first to override the "unset" default
104-
dir_cfg->pass_idtoken_as = type;
105-
}
106-
107-
if (v2) {
108-
rv = oidc_cfg_parse_option(cmd->pool, options, OIDC_CFG_OPTIONS_SIZE(options), v2, (int *)&type);
109-
if (rv != NULL)
110-
return OIDC_CONFIG_DIR_RV(cmd, rv);
111-
dir_cfg->pass_idtoken_as |= type;
112-
}
113-
114-
if (v3) {
115-
rv = oidc_cfg_parse_option(cmd->pool, options, OIDC_CFG_OPTIONS_SIZE(options), v3, (int *)&type);
116-
if (rv != NULL)
117-
return OIDC_CONFIG_DIR_RV(cmd, rv);
118-
dir_cfg->pass_idtoken_as |= type;
106+
if (dir_cfg->pass_idtoken_as == OIDC_CONFIG_POS_INT_UNSET)
107+
dir_cfg->pass_idtoken_as = type;
108+
else
109+
dir_cfg->pass_idtoken_as |= type;
119110
}
120111

121112
return NULL;

src/cfg/dir.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ typedef enum {
7373
/* pass id_token payload as JSON object in header */
7474
OIDC_PASS_IDTOKEN_AS_PAYLOAD = 2,
7575
/* pass id_token in compact serialized format in header */
76-
OIDC_PASS_IDTOKEN_AS_SERIALIZED = 4
76+
OIDC_PASS_IDTOKEN_AS_SERIALIZED = 4,
77+
/* do not pass id_token */
78+
OIDC_PASS_IDTOKEN_OFF = 8
7779
} oidc_pass_idtoken_as_t;
7880

7981
typedef enum {
@@ -146,14 +148,12 @@ OIDC_CFG_DIR_MEMBER_FUNCS(pass_access_token, apr_byte_t)
146148
OIDC_CFG_DIR_MEMBER_FUNCS(pass_refresh_token, apr_byte_t)
147149
OIDC_CFG_DIR_MEMBER_FUNCS(discover_url, const char *)
148150
OIDC_CFG_DIR_MEMBER_FUNCS(state_cookie_prefix, const char *)
151+
OIDC_CFG_DIR_MEMBER_FUNCS(pass_idtoken_as, oidc_pass_idtoken_as_t)
149152

150153
// 2 args
151154
OIDC_CFG_DIR_MEMBER_FUNCS(unautz_action, oidc_unautz_action_t, const char *)
152155
OIDC_CFG_DIR_MEMBER_FUNCS(refresh_access_token_before_expiry, int, const char *)
153156

154-
// 3 args
155-
OIDC_CFG_DIR_MEMBER_FUNCS(pass_idtoken_as, oidc_pass_idtoken_as_t, const char *, const char *)
156-
157157
// ifdefs
158158
#ifdef USE_LIBJQ
159159
OIDC_CFG_DIR_MEMBER_FUNCS(userinfo_claims_expr, const char *)

src/mod_auth_openidc.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,32 @@ apr_byte_t oidc_session_pass_tokens(request_rec *r, oidc_cfg_t *cfg, oidc_sessio
698698
return TRUE;
699699
}
700700

701+
static void oidc_idtoken_pass_as(request_rec *r, oidc_cfg_t *cfg, oidc_session_t *session,
702+
oidc_appinfo_pass_in_t pass_in, oidc_appinfo_encoding_t encoding) {
703+
704+
if ((oidc_cfg_dir_pass_idtoken_as_get(r) & OIDC_PASS_IDTOKEN_OFF))
705+
return;
706+
707+
if ((oidc_cfg_dir_pass_idtoken_as_get(r) & OIDC_PASS_IDTOKEN_AS_CLAIMS)) {
708+
/* set the id_token in the app headers */
709+
oidc_set_app_claims(r, cfg, oidc_session_get_idtoken_claims(r, session));
710+
}
711+
712+
if ((oidc_cfg_dir_pass_idtoken_as_get(r) & OIDC_PASS_IDTOKEN_AS_PAYLOAD)) {
713+
/* pass the id_token JSON object to the app in a header or environment variable */
714+
oidc_util_appinfo_set(r, OIDC_APP_INFO_ID_TOKEN_PAYLOAD,
715+
oidc_util_json_encode(r->pool, oidc_session_get_idtoken_claims(r, session),
716+
JSON_PRESERVE_ORDER | JSON_COMPACT),
717+
OIDC_DEFAULT_HEADER_PREFIX, pass_in, encoding);
718+
}
719+
720+
if ((oidc_cfg_dir_pass_idtoken_as_get(r) & OIDC_PASS_IDTOKEN_AS_SERIALIZED)) {
721+
/* pass the compact serialized JWT to the app in a header or environment variable */
722+
oidc_util_appinfo_set(r, OIDC_APP_INFO_ID_TOKEN, oidc_session_get_idtoken(r, session),
723+
OIDC_DEFAULT_HEADER_PREFIX, pass_in, encoding);
724+
}
725+
}
726+
701727
/*
702728
* handle the case where we have identified an existing authentication session for a user
703729
*/
@@ -788,30 +814,13 @@ static int oidc_handle_existing_session(request_rec *r, oidc_cfg_t *cfg, oidc_se
788814
/* copy id_token and claims from session to request state and obtain their values */
789815
oidc_copy_tokens_to_request_state(r, session);
790816

791-
if ((oidc_cfg_dir_pass_idtoken_as_get(r) & OIDC_PASS_IDTOKEN_AS_CLAIMS)) {
792-
/* set the id_token in the app headers */
793-
if (oidc_set_app_claims(r, cfg, oidc_session_get_idtoken_claims(r, session)) == FALSE)
794-
return HTTP_INTERNAL_SERVER_ERROR;
795-
}
796-
797-
if ((oidc_cfg_dir_pass_idtoken_as_get(r) & OIDC_PASS_IDTOKEN_AS_PAYLOAD)) {
798-
/* pass the id_token JSON object to the app in a header or environment variable */
799-
oidc_util_appinfo_set(r, OIDC_APP_INFO_ID_TOKEN_PAYLOAD,
800-
oidc_util_json_encode(r->pool, oidc_session_get_idtoken_claims(r, session),
801-
JSON_PRESERVE_ORDER | JSON_COMPACT),
802-
OIDC_DEFAULT_HEADER_PREFIX, pass_in, encoding);
803-
}
804-
805-
if ((oidc_cfg_dir_pass_idtoken_as_get(r) & OIDC_PASS_IDTOKEN_AS_SERIALIZED)) {
806-
/* pass the compact serialized JWT to the app in a header or environment variable */
807-
oidc_util_appinfo_set(r, OIDC_APP_INFO_ID_TOKEN, oidc_session_get_idtoken(r, session),
808-
OIDC_DEFAULT_HEADER_PREFIX, pass_in, encoding);
809-
}
810-
811817
/* pass the at, rt and at expiry to the application, possibly update the session expiry */
812818
if (oidc_session_pass_tokens(r, cfg, session, extend_session, needs_save) == FALSE)
813819
return HTTP_INTERNAL_SERVER_ERROR;
814820

821+
/* pass ID token and claims */
822+
oidc_idtoken_pass_as(r, cfg, session, pass_in, encoding);
823+
/* pass userinfo claims */
815824
oidc_userinfo_pass_as(r, cfg, session, pass_in, encoding);
816825

817826
/* return "user authenticated" status */

0 commit comments

Comments
 (0)