Skip to content

Commit 4540b88

Browse files
committed
use strncasecmp on content type when obtaining a token from POST
closes #72; thanks @roubert Signed-off-by: Hans Zandbelt <hans.zandbelt@openidc.com>
1 parent 7914c43 commit 4540b88

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
03/25/2026
2+
- use strncasecmp on content type when obtaining a token from POST; closes #72; thanks @roubert
3+
14
02/03/2026
25
- code: assign strstr to char instead of const char to compile with globc 2.43
36
see #70; thanks @babelouest

src/proto.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ static char *_oauth2_get_source_token_from_post(
138138
oauth2_http_request_header_content_type_get(log, request);
139139
if ((oauth2_http_request_method_get(log, request) !=
140140
OAUTH2_HTTP_METHOD_POST) ||
141-
(strcasecmp(content_type, OAUTH2_CONTENT_TYPE_FORM_ENCODED) != 0)) {
141+
(strncasecmp(content_type, OAUTH2_CONTENT_TYPE_FORM_ENCODED,
142+
strlen(OAUTH2_CONTENT_TYPE_FORM_ENCODED)) != 0)) {
142143
oauth2_debug(log, "no form-encoded HTTP POST");
143144
goto end;
144145
}

test/check_proto.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ START_TEST(test_proto_get_source_token_post)
287287
oauth2_cfg_source_token_free(_log, cfg);
288288

289289
oauth2_http_request_free(_log, request);
290+
291+
// also test for "application/x-www-form-urlencoded;charset=UTF-8" etc.;
292+
// see #72
293+
294+
request = oauth2_http_request_init(_log);
295+
oauth2_http_request_method_set(_log, request, OAUTH2_HTTP_METHOD_POST);
296+
oauth2_http_request_header_set(
297+
_log, request, "Content-Type",
298+
"application/x-www-form-urlencoded;charset=UTF-8");
299+
300+
cfg = oauth2_cfg_source_token_init(_log);
301+
ck_assert_ptr_ne(cfg, NULL);
302+
rv = oauth2_cfg_source_token_set_accept_in(_log, cfg, "post", NULL);
303+
ck_assert_ptr_eq(rv, NULL);
304+
token = oauth2_get_source_token(_log, cfg, request,
305+
&_oauth2_check_proto_callbacks, NULL);
306+
ck_assert_ptr_ne(token, NULL);
307+
ck_assert_str_eq(token, my_post_token);
308+
oauth2_mem_free(token);
309+
oauth2_cfg_source_token_free(_log, cfg);
290310
}
291311
END_TEST
292312

0 commit comments

Comments
 (0)