Cross-site scripting"
Line 16: | Line 16: | ||
<code>Label</code> component's <code>value</code> and those attributes that generate texts into a page including <code>label, title, tooltiptext, placeholder, name, type</code>, and message like <code>createMessage, emptyMessage</code>. (ZK encodes them with <code>zUtl.encodeXML()</code> at client-side.) | <code>Label</code> component's <code>value</code> and those attributes that generate texts into a page including <code>label, title, tooltiptext, placeholder, name, type</code>, and message like <code>createMessage, emptyMessage</code>. (ZK encodes them with <code>zUtl.encodeXML()</code> at client-side.) | ||
− | = | + | = What ZK Doesn't Encode = |
== The <code>content</code> Attribute of Html and Comboitem == | == The <code>content</code> Attribute of Html and Comboitem == | ||
Line 24: | Line 24: | ||
<html>${any_content}</html> | <html>${any_content}</html> | ||
</source> | </source> | ||
− | |||
== Some methods of <code>Clients</code> == | == Some methods of <code>Clients</code> == |
Revision as of 06:56, 19 May 2022
Overview
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications that enables malicious attackers to inject client-side script into web pages viewed by other users. Because HTML documents have a flat, serial structure that mixes control statements, formatting, and the actual content, any non-validated user-supplied data included in the resulting page without proper HTML encoding may lead to markup injection.
What ZK Encodes
All Input Components Block XSS
To prevent a XSS attack, ZK components encode any value that might be input by a user by escaping &
and other unsafe characters. For example, the following statement is totally safe even any_value
contains a script like <script>alert('xss')</script>
:
<textbox value="${any_value}"/>
Attributes to Generate Texts
Label
component's value
and those attributes that generate texts into a page including label, title, tooltiptext, placeholder, name, type
, and message like createMessage, emptyMessage
. (ZK encodes them with zUtl.encodeXML()
at client-side.)
What ZK Doesn't Encode
The content
Attribute of Html and Comboitem
The content property of the html and combitem components (Html.setContent(String) and Comboitem.setContent(String)) are designed to allow applications to generate HTML content directly. In other words, it is not encoded. Thus, it is better not to carry the user input, unless it is encoded properly. For example, if the value of any_content
is, in the following example, generated directly and vulnerable to XSS attack if it is the value provided by an user and without proper encoding.
<html>${any_content}</html>
Some methods of Clients
As the name says this utility allows more direct client-side access. Thus the methods don't encode the strings passed into them to allow formatting of the messages at client-side, e.g.:
Clients.showNotification("Successfully processed: <br/>" + myTextbox.getValue());
When displaying user input using methods such as Clients.showBusy(String) or Clients.showNotification(String) ... and especially when dynamically concatenated JS code is executed using Clients.evalJavaScript(String) user input should be escaped carefully.
Client-side Actions
The client-side action is not encoded and the options are interpreted as a JSON object. Thus, you could encode it by yourself, if you allow the end-user to specify it (which is generally not suggested at all).
Page Directive
All attributes of <?page?> are not encoded.
Sanitize User Input
Regarding those attributes that ZK doesn't escape HTML characters, we assume application developers should do it according to their needs. You can use ZK XMLs.escapeXML(String) or Apache Commons Lang's StringEscapeUtils to sanitize user input.
Version History
Version | Date | Content |
---|---|---|