@@ -413,11 +413,13 @@ static int oidc_http_add_form_url_encoded_param(void* rec, const char* key,
413413static apr_byte_t oidc_util_http_call (request_rec * r , const char * url ,
414414 const char * data , const char * content_type , const char * basic_auth ,
415415 const char * bearer_token , int ssl_validate_server ,
416- const char * * response , int timeout , const char * outgoing_proxy ) {
416+ const char * * response , int timeout , const char * outgoing_proxy ,
417+ apr_array_header_t * pass_cookies ) {
417418 char curlError [CURL_ERROR_SIZE ];
418419 oidc_curl_buffer curlBuffer ;
419420 CURL * curl ;
420421 struct curl_slist * h_list = NULL ;
422+ int i ;
421423
422424 /* do some logging about the inputs */
423425 oidc_debug (r ,
@@ -498,6 +500,28 @@ static apr_byte_t oidc_util_http_call(request_rec *r, const char *url,
498500 if (h_list != NULL )
499501 curl_easy_setopt (curl , CURLOPT_HTTPHEADER , h_list );
500502
503+ /* gather cookies that we need to pass on from the incoming request */
504+ char * cookie_string = NULL ;
505+ for (i = 0 ; i < pass_cookies -> nelts ; i ++ ) {
506+ const char * cookie_name = ((const char * * ) pass_cookies -> elts )[i ];
507+ char * cookie_value = oidc_util_get_cookie (r , cookie_name );
508+ if (cookie_value != NULL ) {
509+ cookie_string =
510+ (cookie_string == NULL ) ?
511+ apr_psprintf (r -> pool , "%s=%s" , cookie_name ,
512+ cookie_value ) :
513+ apr_psprintf (r -> pool , "%s; %s=%s" , cookie_string ,
514+ cookie_name , cookie_value );
515+ }
516+ }
517+
518+ /* see if we need to pass any cookies */
519+ if (cookie_string != NULL ) {
520+ oidc_debug (r , "passing browser cookies on backend call: %s" ,
521+ cookie_string );
522+ curl_easy_setopt (curl , CURLOPT_COOKIE , cookie_string );
523+ }
524+
501525 /* set the target URL */
502526 curl_easy_setopt (curl , CURLOPT_URL , url );
503527
@@ -514,7 +538,7 @@ static apr_byte_t oidc_util_http_call(request_rec *r, const char *url,
514538 /* set and log the response */
515539 oidc_debug (r , "response=%s" , * response );
516540
517- out :
541+ out :
518542
519543 /* cleanup and return the result */
520544 if (h_list != NULL )
@@ -530,7 +554,8 @@ static apr_byte_t oidc_util_http_call(request_rec *r, const char *url,
530554apr_byte_t oidc_util_http_get (request_rec * r , const char * url ,
531555 const apr_table_t * params , const char * basic_auth ,
532556 const char * bearer_token , int ssl_validate_server ,
533- const char * * response , int timeout , const char * outgoing_proxy ) {
557+ const char * * response , int timeout , const char * outgoing_proxy ,
558+ apr_array_header_t * pass_cookies ) {
534559
535560 if ((params != NULL ) && (apr_table_elts (params )-> nelts > 0 )) {
536561 oidc_http_encode_t data = { r , "" };
@@ -541,7 +566,8 @@ apr_byte_t oidc_util_http_get(request_rec *r, const char *url,
541566 }
542567
543568 return oidc_util_http_call (r , url , NULL , NULL , basic_auth , bearer_token ,
544- ssl_validate_server , response , timeout , outgoing_proxy );
569+ ssl_validate_server , response , timeout , outgoing_proxy ,
570+ pass_cookies );
545571}
546572
547573/*
@@ -550,7 +576,8 @@ apr_byte_t oidc_util_http_get(request_rec *r, const char *url,
550576apr_byte_t oidc_util_http_post_form (request_rec * r , const char * url ,
551577 const apr_table_t * params , const char * basic_auth ,
552578 const char * bearer_token , int ssl_validate_server ,
553- const char * * response , int timeout , const char * outgoing_proxy ) {
579+ const char * * response , int timeout , const char * outgoing_proxy ,
580+ apr_array_header_t * pass_cookies ) {
554581
555582 const char * data = NULL ;
556583 if ((params != NULL ) && (apr_table_elts (params )-> nelts > 0 )) {
@@ -563,7 +590,8 @@ apr_byte_t oidc_util_http_post_form(request_rec *r, const char *url,
563590
564591 return oidc_util_http_call (r , url , data ,
565592 "application/x-www-form-urlencoded" , basic_auth , bearer_token ,
566- ssl_validate_server , response , timeout , outgoing_proxy );
593+ ssl_validate_server , response , timeout , outgoing_proxy ,
594+ pass_cookies );
567595}
568596
569597/*
@@ -572,7 +600,7 @@ apr_byte_t oidc_util_http_post_form(request_rec *r, const char *url,
572600apr_byte_t oidc_util_http_post_json (request_rec * r , const char * url ,
573601 const json_t * json , const char * basic_auth , const char * bearer_token ,
574602 int ssl_validate_server , const char * * response , int timeout ,
575- const char * outgoing_proxy ) {
603+ const char * outgoing_proxy , apr_array_header_t * pass_cookies ) {
576604
577605 char * data = NULL ;
578606 if (json != NULL ) {
@@ -583,7 +611,7 @@ apr_byte_t oidc_util_http_post_json(request_rec *r, const char *url,
583611
584612 return oidc_util_http_call (r , url , data , "application/json" , basic_auth ,
585613 bearer_token , ssl_validate_server , response , timeout ,
586- outgoing_proxy );
614+ outgoing_proxy , pass_cookies );
587615}
588616
589617/*
0 commit comments