-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. ZK-5182: Prevent XSS issue in component attributes
2. ZK-5162: emptyMessage is not escaped with HTML characters
- Loading branch information
1 parent
9653c09
commit 035f86e
Showing
36 changed files
with
277 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* SafeHtmlValue.java | ||
Purpose: | ||
Description: | ||
History: | ||
2:39 PM 2023/12/20, Created by jumperchen | ||
Copyright (C) 2023 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zk.ui; | ||
|
||
import java.util.Objects; | ||
|
||
import org.zkoss.json.JSONValue; | ||
|
||
/** | ||
* A string-like value that is safe to be used as HTML content. | ||
* @author jumperchen | ||
* @since 10.0.0 | ||
*/ | ||
public class SafeHtmlValue implements org.zkoss.json.JSONAware, java.io.Serializable { | ||
private static final long serialVersionUID = 202312201440L; | ||
private final String _value; | ||
|
||
/** An empty SafeHtmlValue instance. */ | ||
public static final SafeHtmlValue EMPTY = new SafeHtmlValue(""); | ||
|
||
/** | ||
* Constructor. | ||
* @param value the value to be wrapped. | ||
*/ | ||
public SafeHtmlValue(String value) { | ||
_value = value; | ||
} | ||
|
||
/** | ||
* Returns the wrapped value. | ||
*/ | ||
public String getValue() { | ||
return _value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toJSONString(); | ||
} | ||
|
||
@Override | ||
public String toJSONString() { | ||
return JSONValue.toJSONString(_value); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
SafeHtmlValue that = (SafeHtmlValue) o; | ||
return Objects.equals(_value, that._value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(_value); | ||
} | ||
|
||
/** | ||
* Returns a SafeHtmlValue instance for the specified value. | ||
* @param value the value to be wrapped. | ||
* @since 10.0.0 | ||
*/ | ||
public static SafeHtmlValue valueOf(String value) { | ||
return new SafeHtmlValue(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
B100-ZK-5162.zul | ||
Purpose: | ||
Description: | ||
History: | ||
2023/12/20, Created by jumperchen | ||
Copyright (C) 2023 Potix Corporation. All Rights Reserved. | ||
--> | ||
<zk> | ||
<zscript><![CDATA[ | ||
String message = "</span><script>alert('XSS')</script>"; //might read from an external source | ||
String script = "<script>alert('XSS')</script>"; | ||
]]></zscript> | ||
<grid emptyMessage="${script}"> | ||
</grid> | ||
<listbox emptyMessage="${script}"/> | ||
</zk> |
38 changes: 38 additions & 0 deletions
38
zktest/src/test/java/org/zkoss/zktest/zats/test2/B100_ZK_5162Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* B100_ZK_5162Test.java | ||
Purpose: | ||
Description: | ||
History: | ||
11:57 AM 2023/12/20, Created by jumperchen | ||
Copyright (C) 2023 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.zats.test2; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.NoAlertPresentException; | ||
|
||
import org.zkoss.test.webdriver.WebDriverTestCase; | ||
|
||
/** | ||
* @author jumperchen | ||
*/ | ||
public class B100_ZK_5162Test extends WebDriverTestCase { | ||
@Test | ||
public void test() { | ||
connect(); | ||
try { | ||
driver.switchTo().alert(); | ||
fail("Should not be here"); | ||
} catch (NoAlertPresentException ex) { | ||
// ignore | ||
} | ||
assertEquals("<script>alert('XSS')</script>", jq(".z-grid-emptybody-content").text()); | ||
assertEquals("<script>alert('XSS')</script>", jq(".z-listbox-emptybody-content").text()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.