@@ -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+ { "&" , "'" , """ , ">" , "<" , };
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 */
10371067int 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