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

Cherry-pick: Test for xss attack (#5519) #5521

Merged
merged 1 commit into from
Apr 18, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,35 @@
import com.vaadin.flow.testutil.ChromeBrowserTest;

public class RouteNotFoundIT extends ChromeBrowserTest {
/*
Original script:
<img src=x onerror=(function(){d=document.createElement("DIV");document.body.appendChild(d);d.id="injected";})()>
*/
private static final String INJECT_ATTACK = "%3Cimg%20src%3Dx%20onerror" +
"%3D%28function%28%29%7Bd%3Ddocument.createElement%28%22DIV%22%" +
"29%3Bdocument.body.appendChild%28d%29%3Bd.id%3D%22injected%22%" +
"3B%7D%29%28%29%3E";

@Test
public void notFoundDevMode() {
getDriver().get(getRootURL() + "/view/notfound");
getDriver().get(getRootURL() + "/view/notfound/" + INJECT_ATTACK);
String pageSource = getDriver().getPageSource();
Assert.assertTrue(pageSource.contains("Available routes"));
Assert.assertTrue(pageSource.contains("noParent"));
Assert.assertTrue(pageSource.contains("foo/bar"));
// check that <img src=x onerror=...> did not inject div via script
Assert.assertFalse(pageSource.contains("<div id=\"injected\"></div>"));
}

@Test
public void notFoundProdMode() {
getDriver().get(getRootURL() + "/view-production/notfound");
getDriver().get(getRootURL() + "/view-production/notfound/" + INJECT_ATTACK);
String pageSource = getDriver().getPageSource();
Assert.assertFalse(pageSource.contains("Available routes"));
Assert.assertFalse(pageSource.contains("noParent"));
Assert.assertFalse(pageSource.contains("foo/bar"));
// check that <img src=x onerror=...> did not inject div via script
Assert.assertFalse(pageSource.contains("<div id=\"injected\"></div>"));
}

}