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

fix: escape uri in module side #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions share/status.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ <h1>
? '<img class="flag flag-{}" />'.format(name.toLowerCase())
: '';

s = '{}{}'.format(aHe('th', encodeURI('{}{}'.format(flag, name))),
s = '{}{}'.format(aHe('th', '{}{}'.format(flag, name)),
aHe('td', [(zone.requestCounter + zone.overCounts['maxIntegerSize'] * zone.overCounts['requestCounter']),
aPs.getValue('{}.{}'.format(uniq, 'requestCounter'), zone.requestCounter), mTh(zone.requestMsec)
]));
Expand Down Expand Up @@ -681,7 +681,7 @@ <h1>

clas = (n++ % 2) ? 'odd' : '';

s = '{}{}'.format(aHe('th', encodeURI(peer.server)),
s = '{}{}'.format(aHe('th', peer.server),
aHe('td', [sTh(peer.backup, peer.down), mTh(peer.responseMsec),
peer.weight, peer.maxFails, peer.failTimeout,
(peer.requestCounter + peer.overCounts['maxIntegerSize'] * peer.overCounts['requestCounter']),
Expand Down Expand Up @@ -722,7 +722,7 @@ <h1>

clas = (n++ % 2) ? 'odd' : '';

s = '{}{}'.format(aHe('th', encodeURI(name)),
s = '{}{}'.format(aHe('th', name),
aHe('td', [bTh(zone.maxSize),
bTh(zone.usedSize),
bTh(zone.outBytes + zone.overCounts['maxIntegerSize'] * zone.overCounts['outBytes']),
Expand Down
33 changes: 33 additions & 0 deletions src/ngx_http_vhost_traffic_status_display_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ ngx_http_vhost_traffic_status_display_set_server_node(
}

#if (NGX_HTTP_CACHE)
ngx_http_vhost_traffic_status_display_encode_uri(r, &dst);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER,
&dst, vtsn->stat_request_counter,
vtsn->stat_in_bytes,
Expand Down Expand Up @@ -140,6 +141,7 @@ ngx_http_vhost_traffic_status_display_set_server_node(
vtsn->stat_cache_scarce_counter_oc,
vtsn->stat_request_time_counter_oc);
#else
ngx_http_vhost_traffic_status_display_encode_uri(r, &dst);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER,
&dst, vtsn->stat_request_counter,
vtsn->stat_in_bytes,
Expand Down Expand Up @@ -286,6 +288,31 @@ ngx_http_vhost_traffic_status_display_set_filter_node(ngx_http_request_t *r,
return ngx_http_vhost_traffic_status_display_set_server_node(r, buf, &key, vtsn);
}

void
ngx_http_vhost_traffic_status_display_encode_uri(ngx_http_request_t *r,
ngx_str_t *uri)
{

size_t len;
ngx_str_t *euri;
u_char *p;
euri = uri;
len = ngx_escape_html(NULL, uri->data, uri->len);

if (len) {
p = ngx_pnalloc(r->pool, uri->len + len);
if (p == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"display_encode_uri::ngx_pnalloc() failed");
}

(void) ngx_escape_html(p, uri->data, uri->len);
euri->data = p;
euri->len = uri->len + len;
uri = euri;
}
return;
}

u_char *
ngx_http_vhost_traffic_status_display_set_filter(ngx_http_request_t *r,
Expand Down Expand Up @@ -332,6 +359,7 @@ ngx_http_vhost_traffic_status_display_set_filter(ngx_http_request_t *r,
"display_set_filter::escape_json_pool() failed");
}

ngx_http_vhost_traffic_status_display_encode_uri(r, &filter);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_OBJECT_S,
&filter);

Expand Down Expand Up @@ -392,6 +420,7 @@ ngx_http_vhost_traffic_status_display_set_upstream_node(ngx_http_request_t *r,
}

if (vtsn != NULL) {
ngx_http_vhost_traffic_status_display_encode_uri(r, &key);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_UPSTREAM,
&key, vtsn->stat_request_counter,
vtsn->stat_in_bytes, vtsn->stat_out_bytes,
Expand Down Expand Up @@ -434,6 +463,7 @@ ngx_http_vhost_traffic_status_display_set_upstream_node(ngx_http_request_t *r,
vtsn->stat_request_time_counter_oc, vtsn->stat_response_time_counter_oc);

} else {
ngx_http_vhost_traffic_status_display_encode_uri(r, &key);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_UPSTREAM,
&key, (ngx_atomic_uint_t) 0,
(ngx_atomic_uint_t) 0, (ngx_atomic_uint_t) 0,
Expand Down Expand Up @@ -563,6 +593,7 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r,

o = buf;

ngx_http_vhost_traffic_status_display_encode_uri(r, &uscf->host);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_ARRAY_S,
&uscf->host);
s = buf;
Expand Down Expand Up @@ -703,6 +734,7 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r,

ngx_str_set(&key, "::nogroups");

ngx_http_vhost_traffic_status_display_encode_uri(r, &key);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_ARRAY_S, &key);

s = buf;
Expand Down Expand Up @@ -742,6 +774,7 @@ u_char
"display_set_cache_node::escape_json_pool() failed");
}

ngx_http_vhost_traffic_status_display_encode_uri(r, &key);
buf = ngx_sprintf(buf, NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_CACHE,
&key, vtsn->stat_cache_max_size,
vtsn->stat_cache_used_size,
Expand Down
2 changes: 2 additions & 0 deletions src/ngx_http_vhost_traffic_status_display_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ u_char *ngx_http_vhost_traffic_status_display_set_cache(
u_char *ngx_http_vhost_traffic_status_display_set(ngx_http_request_t *r,
u_char *buf);

void ngx_http_vhost_traffic_status_display_encode_uri(
ngx_http_request_t *r, ngx_str_t *uri);

#endif /* _NGX_HTTP_VTS_DISPLAY_JSON_H_INCLUDED_ */

Expand Down
Loading
Loading