Skip to content

Commit

Permalink
[FIX JENKINS-31616] Prohibit scheme-relative URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Dec 20, 2015
1 parent fa144c7 commit bf3758d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/hudson/markup/MyspacePolicy.java
Expand Up @@ -20,7 +20,7 @@ public class MyspacePolicy {
public static final PolicyFactory POLICY_DEFINITION;

private static final Pattern ONSITE_URL = Pattern.compile(
"(?:[\\p{L}\\p{N}\\\\\\.\\#@\\$%\\+&;\\-_~,\\?=/!]+|\\#(\\w)+)");
"(?!//)(?:[\\p{L}\\p{N}\\\\\\.\\#@\\$%\\+&;\\-_~,\\?=/!]+|\\#(\\w)+)");
private static final Pattern OFFSITE_URL = Pattern.compile(
"\\s*(?:(?:ht|f)tps?://|mailto:)[\\p{L}\\p{N}]"
+ "[\\p{L}\\p{N}\\p{Zs}\\.\\#@\\$%\\+&;:\\-_~,\\?=/!\\(\\)]*\\s*");
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/hudson/markup/MyspacePolicyTest.java
Expand Up @@ -48,6 +48,11 @@ public void testPolicy() {
assertReject("sun.com", "<form method='post' action='http://sun.com/'><input type='text' name='foo'><input type='password' name='pass'></form>");
}

@Test
public void testProtocolRelativeUrl() {
assertReject("action", "<form action='//example.org/evil.php'><input type='submit'/></form>");
}

private void assertIntact(String input) {
input = input.replace('\'','\"');
assertSanitize(input,input);
Expand Down

0 comments on commit bf3758d

Please sign in to comment.