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

[SUP-1666] [java6] add jsoup.clean to removeForm() htmlreplacemarker function #211

Merged
merged 5 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ build:

.PHONY: start_local
start_local:
cd docker/java6; make USE_LOCAL_BUILD=yes WOVN_VERSION=1.0.7-jdk6 && docker-compose up; cd -;
cd docker/java6; make USE_LOCAL_BUILD=yes WOVN_VERSION=1.0.8-jdk6 && docker-compose up; cd -;
2 changes: 1 addition & 1 deletion docker/java6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c

USE_LOCAL_BUILD ?= no
WOVN_VERSION ?= 1.0.7-jdk6
WOVN_VERSION ?= 1.0.8-jdk6
PROJECT_NAME = hello
PROJECT_LIB_PATH = $(PROJECT_NAME)/src/main/webapp/WEB-INF/lib

Expand Down
2 changes: 1 addition & 1 deletion docker/java6/hello/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>com.github.wovnio</groupId>
<artifactId>wovnjava</artifactId>
<version>1.0.7-jdk6</version>
<version>1.0.8-jdk6</version>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.github.wovnio</groupId>
<artifactId>wovnjava</artifactId>
<name>wovnjava</name>
<version>1.0.7-jdk6</version>
<version>1.0.8-jdk6</version>
<url>https://github.com/WOVNio/wovnjava</url>

<licenses>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/github/wovnio/wovnjava/HtmlConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jsoup.nodes.Element;
import org.jsoup.parser.Tag;
import org.jsoup.select.Elements;
import org.jsoup.safety.Whitelist;

class HtmlConverter {
private final Document doc;
Expand Down Expand Up @@ -106,7 +107,7 @@ private void removeForm() {
String type = element.attr("type");
if (type != null && type.toLowerCase().equals("hidden")) {
if (element.hasAttr("value")) {
String original = element.attr("value");
String original = Jsoup.clean(element.attr("value"), Whitelist.none());
String key = htmlReplaceMarker.generateKey();
element.removeAttr("value").removeAttr("VALUE");
element.attr("value", key);
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/github/wovnio/wovnjava/HtmlConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public void testRemoveForm() throws ConfigurationError {
assertEquals(original.replace("INPUT", "input").replace("VALUE", "value"), stripExtraSpaces(converter.restore(html)));
}

public void testRemoveForm__Sanitize() throws ConfigurationError {
String original = "<html lang=\"en\"><head></head><body><form><input type=\"hidden\" name=\"csrf\" value=\"&quot;&gt;&lt;script &gt;alert(String.fromCharCode(88,83,83))&lt;/script&gt;\"></form></body></html>";
String sanitized = "<html lang=\"en\"><head></head><body><form><input type=\"hidden\" name=\"csrf\" value=\"\"&gt;\"></form></body></html>";
Settings settings = TestUtil.makeSettings(new HashMap<String, String>() {{ put("supportedLangs", "en,fr,ja"); }});
HtmlConverter converter = this.createHtmlConverter(settings, location, original);
String html = converter.strip();

assertEquals(sanitized, stripExtraSpaces(converter.restore(html)));
}

public void testNested() throws ConfigurationError {
String original = "<html><head></head><body><form wovn-ignore><script></script><input type=\"hidden\" name=\"csrf\" value=\"random\"><INPUT TYPE=\"HIDDEN\" NAME=\"CSRF_TOKEN\" VALUE=\"RANDOM\"></form></body></html>";
String removedHtml = "<html><head></head><body><form wovn-ignore><!--wovn-marker-1--></form></body></html>";
Expand Down