Skip to content

Cleaner may make input document URLs absolute; should have no side effects #2475

Description

@jhy

I found an undesired side effect in Cleaner; when working with a Document, some calls could update URL attributes on the input document instead of only on the cleaned output.

For example, with a standard safelist like Safelist.basic(), cleaning or validating a document containing a relative link could rewrite the input href to an absolute URL:

Document dirty = Jsoup.parseBodyFragment(
  "<a href='/foo'>One</a>", "https://example.com/");
Cleaner cleaner = new Cleaner(Safelist.basic());

cleaner.clean(dirty);   // or cleaner.isValid(dirty)

dirty.expectFirst("a").attr("href"); // became "https://example.com/foo"

The intention is that absolutizing applies only to the cleaned output document. The input document should be left as-is.

The fix is to remove side effects from Safelist attribute/protocol checks, and make Cleaner perform URL normalization explicitly when copying safe attributes into the output document.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugA confirmed bug, that we should fixfixedAn {bug|improvement} that has been {fixed|implemented}

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions