Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/oidc_child/oidc_child_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ errno_t keycloak_lookup(TALLOC_CTX *mem_ctx, enum oidc_cmd oidc_cmd,
char *input_enc;
const char *obj_id;
char *short_name;
char *short_name_enc;
char *sep;
struct name_and_type_identifier keycloak_name_and_type_identifier = {
.user_identifier_attr = "username",
Expand All @@ -339,7 +340,7 @@ errno_t keycloak_lookup(TALLOC_CTX *mem_ctx, enum oidc_cmd oidc_cmd,
case GET_GROUP:
case GET_GROUP_MEMBERS:
sep = strrchr(input, '@');
if (sep == NULL && sep != input) {
if (sep == NULL || sep == input) {
filter = talloc_asprintf(rest_ctx, "search=%s&exact=true&populateHierarchy=false&briefRepresentation=false", input_enc);
} else {
short_name = talloc_strndup(rest_ctx, input, sep - input);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The extracted short_name is used directly in the Keycloak search filter query string without being URL-encoded. If the group name contains special characters (such as spaces, &, or #), this will result in an invalid URL or potentially parameter injection. We should URL-encode the short_name after duplicating it, similar to how input_enc is handled.

            char *short_name_raw = talloc_strndup(rest_ctx, input, sep - input);
            if (short_name_raw == NULL) {
                short_name = NULL;
            } else {
                short_name = url_encode_string(rest_ctx, short_name_raw);
                talloc_free(short_name_raw);
            }

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.

Hi,

thank you for fixing the logic issues. The comment from Gemini is valid, would you like to add a fix for this as well?

bye,
Sumit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok. PR has been updated according to Gemini comment.

Expand All @@ -350,8 +351,17 @@ errno_t keycloak_lookup(TALLOC_CTX *mem_ctx, enum oidc_cmd oidc_cmd,
filter = talloc_asprintf(rest_ctx, "search=%s&exact=true",
input_enc);
} else {
filter = talloc_asprintf(rest_ctx, "search=%s&exact=true",
short_name);
short_name_enc = url_encode_string(rest_ctx, short_name);
if (short_name_enc == NULL) {
DEBUG(SSSDBG_OP_FAILURE,
"Failed to encode short name, using plain input [%s].\n",
input);
filter = talloc_asprintf(rest_ctx, "search=%s&exact=true",
input_enc);
} else {
filter = talloc_asprintf(rest_ctx, "search=%s&exact=true",
short_name_enc);
}
}
}
break;
Expand Down
Loading