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

Array out of bounds exception on HtmlPolicyBuilder initialization #247

Open
mymhealthltd-joshengland opened this issue Jan 24, 2022 · 0 comments

Comments

@mymhealthltd-joshengland
Copy link
Contributor

mymhealthltd-joshengland commented Jan 24, 2022

Constructing a HtmlPolicyBuilder zero-defined global attributes, globally, leads to an Arry out of bounds exception

Here is sample code that produces the problem

new HtmlPolicyBuilder().allowElements().allowAttributes().globally().toFactory();

The exception comes form an un-guarded check on the zeroth element of the attributesNames list. In this situation, attribute names is empty and so has no zeroth element.

    public HtmlPolicyBuilder globally() {
      if(attributeNames.get(0).equals("style")) {
        return allowStyling();
      } else {
        return HtmlPolicyBuilder.this.allowAttributesGlobally(
            policy, attributeNames);
      }
    }

This construction used to work in version 20180219.1 of this library but is broken in 20211018.2.

mymhealthltd-joshengland added a commit to mymhealthltd-joshengland/java-html-sanitizer that referenced this issue Jan 24, 2022
Add guard to .globally() method of HtmlPolicyBuilder to prevent
ArrayOutOfBoundsException when checking to see if the zeroth
element of the attributeNames list contains 'style'.

This restores behaviour present in version 202180219.1 which
allowed for an empty allowed attributes names list to be
specified globally through the builder.
mikesamuel added a commit that referenced this issue Feb 2, 2024
* Fix allowAttributes().globally() (#247)

Add guard to .globally() method of HtmlPolicyBuilder to prevent
ArrayOutOfBoundsException when checking to see if the zeroth
element of the attributeNames list contains 'style'.

This restores behaviour present in version 202180219.1 which
allowed for an empty allowed attributes names list to be
specified globally through the builder.

* Allow styling when any attribute name matches "style" globally

---------

Co-authored-by: Mike Samuel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant