Skip to content

Commit 98d7b23

Browse files
authored
Merge pull request #597 from bitsolve/add_ivp6_support
Add support for ipv6
2 parents a25093a + 2699a2e commit 98d7b23

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ reporting bugs, providing fixes, suggesting useful features or other:
7070
Harri Rautila <https://github.com/hrautila>
7171
Tatsuhiko Yasumatsu <https://github.com/ty60>
7272
Adam Stadler <https://github.com/tzfx>
73+
Steffen Greber <https://github.com/codemaker219>

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
06/04/2021
2+
- fix a problem where the host and port are calculated incorrectly, when you use literal ipv6 address.
3+
14
06/02/2021
25
- do not send state timeout HTML document when OIDCDefaultURL is set; this can be overridden by using e.g.:
36
SetEnvIfExpr true OIDC_NO_DEFAULT_URL_ON_STATE_TIMEOUT=true

src/util.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,27 @@ static const char* oidc_get_current_url_scheme(const request_rec *r) {
387387
return scheme_str;
388388
}
389389

390+
/*
391+
* get the Port part that is currently being accessed
392+
*/
393+
static const char* oidc_get_port_from_host( const char *host_hdr){
394+
char *p = NULL;
395+
char *i = NULL;
396+
397+
if (host_hdr) {
398+
if (host_hdr[0]=='[') {
399+
i = strchr(host_hdr, ']');
400+
p = strchr(i, OIDC_CHAR_COLON);
401+
} else {
402+
p = strchr(host_hdr, OIDC_CHAR_COLON);
403+
}
404+
}
405+
if (p)
406+
return p;
407+
else
408+
return NULL;
409+
}
410+
390411
/*
391412
* get the URL port that is currently being accessed
392413
*/
@@ -407,7 +428,7 @@ static const char* oidc_get_current_url_port(const request_rec *r,
407428
*/
408429
const char *host_hdr = oidc_util_hdr_in_x_forwarded_host_get(r);
409430
if (host_hdr) {
410-
port_str = strchr(host_hdr, OIDC_CHAR_COLON);
431+
port_str = oidc_get_port_from_host(host_hdr);
411432
if (port_str)
412433
port_str++;
413434
return port_str;
@@ -419,7 +440,7 @@ static const char* oidc_get_current_url_port(const request_rec *r,
419440
*/
420441
host_hdr = oidc_util_hdr_in_host_get(r);
421442
if (host_hdr) {
422-
port_str = strchr(host_hdr, OIDC_CHAR_COLON);
443+
port_str = oidc_get_port_from_host(host_hdr);
423444
if (port_str) {
424445
port_str++;
425446
return port_str;
@@ -452,13 +473,22 @@ static const char* oidc_get_current_url_port(const request_rec *r,
452473
*/
453474
const char* oidc_get_current_url_host(request_rec *r) {
454475
const char *host_str = oidc_util_hdr_in_x_forwarded_host_get(r);
476+
char *p = NULL;
477+
char *i = NULL;
455478
if (host_str == NULL)
456479
host_str = oidc_util_hdr_in_host_get(r);
457480
if (host_str) {
458481
host_str = apr_pstrdup(r->pool, host_str);
459-
char *p = strchr(host_str, OIDC_CHAR_COLON);
460-
if (p != NULL)
461-
*p = '\0';
482+
483+
if (host_str[0] == '[') {
484+
i= strchr(host_str, ']');
485+
p = strchr(i, OIDC_CHAR_COLON);
486+
} else {
487+
p = strchr(host_str, OIDC_CHAR_COLON);
488+
}
489+
490+
if (p != NULL)
491+
*p = '\0';
462492
} else {
463493
/* no Host header, HTTP 1.0 */
464494
host_str = ap_get_server_name(r);

test/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,16 @@ static char * test_current_url(request_rec *r) {
12851285
TST_ASSERT_STR("test_current_url (8)", url,
12861286
"http://remotehost:8380/private/?foo=bar&param1=value1");
12871287

1288+
apr_table_set(r->headers_in, "Host", "[fd04:41b1:1170:28:16b0:446b:9fb7:7118]:8380");
1289+
url = oidc_get_current_url(r);
1290+
TST_ASSERT_STR("test_current_url (9)", url,
1291+
"http://[fd04:41b1:1170:28:16b0:446b:9fb7:7118]:8380/private/?foo=bar&param1=value1");
1292+
1293+
apr_table_set(r->headers_in, "Host", "[fd04:41b1:1170:28:16b0:446b:9fb7:7118]");
1294+
url = oidc_get_current_url(r);
1295+
TST_ASSERT_STR("test_current_url (10)", url,
1296+
"http://[fd04:41b1:1170:28:16b0:446b:9fb7:7118]/private/?foo=bar&param1=value1");
1297+
12881298
return 0;
12891299
}
12901300

0 commit comments

Comments
 (0)