Shawn Grigson
08/22/2024, 2:45 PMtry {
safeHTML = policy.sanitize( untrusted_string );
} catch (any e) {
if ( e.message is "The sanitize method was not found."
or ( e.message == "No matching Method for sanitize(string) found for org.owasp.html.HtmlPolicyBuilder" )
or ( left(e.message,31) is "No matching Method/Function for" and right(e.message,55) is "org.owasp.html.HtmlPolicyBuilder.sanitize(string) found" ) ) {
safeHTML = getPolicy( policy ).sanitize( untrusted_string )
} else {
rethrow;
}
}Shawn Grigson
08/22/2024, 2:45 PMShawn Grigson
08/22/2024, 2:45 PMShawn Grigson
08/22/2024, 2:46 PMShawn Grigson
08/22/2024, 2:46 PMShawn Grigson
08/22/2024, 2:49 PMShawn Grigson
08/22/2024, 2:50 PMShawn Grigson
08/22/2024, 3:40 PMShawn Grigson
08/22/2024, 3:41 PMShawn Grigson
08/22/2024, 3:46 PMShawn Grigson
08/22/2024, 3:49 PMvar safeHTML = "";
try {
safeHTML = policy.sanitize( untrusted_string );
} catch (java.lang.NoSuchMethodException e) {
safeHTML = getPolicy( policy ).sanitize( untrusted_string )
} catch (any e) {
rethrow;
}
return safeHTML;Shawn Grigson
08/22/2024, 3:51 PMrethrow, and the rethrow condition will throw the original error line inside the try block to the page.
Nothing is broken, per se. Though still a minor regression. It was a gotcha that I encountered because of looking for a specific error message string.
I'll just rewrite the code, and we're good.
Thanks for being my rubber duck everyone.Shawn Grigson
08/22/2024, 4:03 PMShawn Grigson
08/22/2024, 4:29 PMtry {
safeHTML = policy.sanitize( untrusted_string );
} catch (java.lang.NoSuchMethodException e) {
safeHTML = getPolicy( policy ).sanitize( untrusted_string );
} catch(expression e) {
safeHTML = getPolicy( policy ).sanitize( untrusted_string );
} catch (any e) {
rethrow;
}