Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add escaping for base_uri #650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 30 additions & 5 deletions ngx_http_vod_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ ngx_http_vod_get_base_url(
ngx_flag_t use_https;
ngx_str_t base_url;
ngx_str_t* host_name = NULL;
uintptr_t escape;
size_t uri_path_len;
size_t result_size;
u_char* last_slash;
Expand All @@ -213,6 +214,7 @@ ngx_http_vod_get_base_url(
file_uri = &empty_string;
}

escape = ngx_escape_uri(NULL, base_url.data, base_url.len, NGX_ESCAPE_URI);
result_size = base_url.len;
}
else
Expand All @@ -225,6 +227,7 @@ ngx_http_vod_get_base_url(

host_name = &r->headers_in.host->value;

escape = ngx_escape_uri(NULL, host_name->data, host_name->len, NGX_ESCAPE_URI);
result_size = sizeof("https://") - 1 + host_name->len;
}

Expand All @@ -233,20 +236,21 @@ ngx_http_vod_get_base_url(
last_slash = ngx_http_vod_memrchr(file_uri->data, '/', file_uri->len);
if (last_slash == NULL)
{
vod_log_error(VOD_LOG_ERR, r->connection->log, 0,
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"ngx_http_vod_get_base_url: no slash found in uri %V", file_uri);
return NGX_ERROR;
}

uri_path_len = last_slash + 1 - file_uri->data;
escape += ngx_escape_uri(NULL, file_uri->data, uri_path_len, NGX_ESCAPE_URI);
}
else
{
uri_path_len = 0;
}

// allocate the base url
result_size += uri_path_len + sizeof("/");
result_size += uri_path_len + sizeof("/") + escape;
p = ngx_palloc(r->pool, result_size);
if (p == NULL)
{
Expand All @@ -260,7 +264,14 @@ ngx_http_vod_get_base_url(

if (conf_base_url != NULL)
{
p = vod_copy(p, base_url.data, base_url.len);
if (escape == 0)
{
p = ngx_copy(p, base_url.data, base_url.len);
}
else
{
p = (u_char*)ngx_escape_uri(p, base_url.data, base_url.len, NGX_ESCAPE_URI);
}
}
else
{
Expand All @@ -279,10 +290,24 @@ ngx_http_vod_get_base_url(
p = ngx_copy(p, "http://", sizeof("http://") - 1);
}

p = ngx_copy(p, host_name->data, host_name->len);
if (escape == 0)
{
p = ngx_copy(p, host_name->data, host_name->len);
}
else
{
p = (u_char*)ngx_escape_uri(p, host_name->data, host_name->len, NGX_ESCAPE_URI);
}
}

p = ngx_copy(p, file_uri->data, uri_path_len);
if (escape == 0)
{
p = ngx_copy(p, file_uri->data, uri_path_len);
}
else
{
p = (u_char*)ngx_escape_uri(p, file_uri->data, uri_path_len, NGX_ESCAPE_URI);
}
*p = '\0';

result->len = p - result->data;
Expand Down