Skip to content

Commit 7015a70

Browse files
author
Hans Zandbelt
committed
1.6.0rc4: apply html encoding to error display
1 parent 9c0b7b5 commit 7015a70

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
10/6/2014
2+
- apply html encoding to error display
3+
- bump version number to 1.6.0rc4
4+
15
10/2/2014
26
- avoid crash when downloading metadata from OIDCProviderMetadataURL fails
37
- set OIDCProviderMetadataURL retrieval interval to 24 hours

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([mod_auth_openidc],[1.6.0rc3],[[email protected]])
1+
AC_INIT([mod_auth_openidc],[1.6.0rc4],[[email protected]])
22

33
AC_SUBST(NAMEVER, AC_PACKAGE_TARNAME()-AC_PACKAGE_VERSION())
44

src/mod_auth_openidc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ apr_byte_t oidc_util_spaced_string_equals(apr_pool_t *pool, const char *a, const
368368
apr_byte_t oidc_util_spaced_string_contains(apr_pool_t *pool, const char *response_type, const char *match);
369369
apr_byte_t oidc_json_object_get_string(apr_pool_t *pool, json_t *json, const char *name, char **value, const char *default_value);
370370
apr_byte_t oidc_json_object_get_int(apr_pool_t *pool, json_t *json, const char *name, int *value, const int default_value);
371+
char *oidc_util_html_escape(apr_pool_t *pool, const char *input);
371372

372373
// oidc_crypto.c
373374
unsigned char *oidc_crypto_aes_encrypt(request_rec *r, oidc_cfg *cfg, unsigned char *plaintext, int *len);

src/proto.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ int oidc_proto_authorization_request_post_preserve(request_rec *r,
7272
return HTTP_INTERNAL_SERVER_ERROR;
7373
}
7474

75-
// TODO: html encode names/values
7675
const apr_array_header_t *arr = apr_table_elts(params);
7776
const apr_table_entry_t *elts = (const apr_table_entry_t*) arr->elts;
7877
int i;
7978
char *json = "";
8079
for (i = 0; i < arr->nelts; i++) {
81-
json = apr_psprintf(r->pool, "%s'%s': '%s'%s", json, elts[i].key,
82-
elts[i].val, i < arr->nelts - 1 ? "," : "");
80+
json = apr_psprintf(r->pool, "%s'%s': '%s'%s", json,
81+
oidc_util_html_escape(r->pool, elts[i].key),
82+
oidc_util_html_escape(r->pool, elts[i].val),
83+
i < arr->nelts - 1 ? "," : "");
8384
}
8485
json = apr_psprintf(r->pool, "{ %s }", json);
8586

src/util.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,36 @@ char *oidc_util_unescape_string(const request_rec *r, const char *str) {
266266
return rv;
267267
}
268268

269+
/*
270+
* HTML escape a string
271+
*/
272+
char *oidc_util_html_escape(apr_pool_t *pool, const char *s) {
273+
const char chars[6] = { '&', '\'', '\"', '>', '<', '\0' };
274+
const char * const replace[] =
275+
{ "&amp;", "&apos;", "&quot;", "&gt;", "&lt;", };
276+
unsigned int i, j = 0, k, n = 0, len = strlen(chars);
277+
int m = 0;
278+
char *r = apr_pcalloc(pool, strlen(s) * 6);
279+
for (i = 0; i < strlen(s); i++) {
280+
for (n = 0; n < len; n++) {
281+
if (s[i] == chars[n]) {
282+
m = strlen(replace[n]);
283+
for (k = 0; k < m; k++)
284+
r[j + k] = replace[n][k];
285+
j += m;
286+
break;
287+
}
288+
}
289+
if (n == len) {
290+
r[j] = s[i];
291+
j++;
292+
}
293+
}
294+
r[j] = '\0';
295+
return apr_pstrdup(pool, r);
296+
}
297+
298+
269299
/*
270300
* get the URL scheme that is currently being accessed
271301
*/
@@ -1036,17 +1066,20 @@ apr_byte_t oidc_util_issuer_match(const char *a, const char *b) {
10361066
*/
10371067
int oidc_util_html_send_error(request_rec *r, const char *error,
10381068
const char *description, int status_code) {
1039-
char *msg = "<p>the OpenID Connect Provider returned an error:</p><p>";
1069+
char *msg =
1070+
"<html><body><p>the OpenID Connect Provider returned an error:</p>";
10401071

10411072
if (error != NULL) {
10421073
msg = apr_psprintf(r->pool, "%s<p>Error: <pre>%s</pre></p>", msg,
1043-
error);
1074+
oidc_util_html_escape(r->pool, error));
10441075
}
10451076
if (description != NULL) {
10461077
msg = apr_psprintf(r->pool, "%s<p>Description: <pre>%s</pre></p>", msg,
1047-
description);
1078+
oidc_util_html_escape(r->pool, description));
10481079
}
10491080

1081+
msg = apr_psprintf(r->pool, "%s</body></html>", msg);
1082+
10501083
return oidc_util_html_send(r, msg, status_code);
10511084
}
10521085

0 commit comments

Comments
 (0)