Block Request for Inaccessible Widgets"

From Documentation
 
(17 intermediate revisions by 3 users not shown)
Line 5: Line 5:
  
  
= Non-existed Component is Safer than Invisible One =
+
= Non-existing Components are Safer than Invisible Ones =
Users can easily access inaccessible elements (such as disabled or invisible ones) by a browser developer tool. For example, a hostile user can make an invisible button visible and then click it to trigger unexpected actions. Thus, it is recommended not to create an element if it is not supposed to be accessible. For example, the first statement is safer than the second one in the following example:
+
Users can easily access inaccessible elements (such as disabled or invisible ones) with a browser developer tool. For example, a hostile user can make an invisible button visible and then click it to trigger unexpected actions. Thus, it is recommended not to create an element if it is not supposed to be accessible. For example, the first statement is safer than the second one in the following example:
  
 
<source lang="xml">
 
<source lang="xml">
Line 13: Line 13:
 
</source>
 
</source>
  
= Block with <tt>InaccessibleWidgetBlockService</tt> =
+
= Block with <code>InaccessibleWidgetBlockService</code> =
 
{{versionSince|5.0.0}}
 
{{versionSince|5.0.0}}
 
{{ZK EE}}  
 
{{ZK EE}}  
  
If you want to block a request for inaccessible widgets for the whole application or for a particular desktop, you can implement the <tt>org.zkoss.zk.au.AuService</tt> interface to filter out unwanted requests. ZK Enterprise Edition has provided a simple implementation called <javadoc>org.zkoss.zkmax.au.InaccessibleWidgetBlockService</javadoc>. To apply it to the whole application, just specify the following in <tt>WEB-INF/zk.xml</tt> as follows.
+
 
 +
ZK provides the `<javadoc>org.zkoss.zkmax.au.InaccessibleWidgetBlockService</javadoc>` to block events sent from inaccessible widgets with a default set of rules. An inaccessible widget is defined as one that is either disabled, invisible, or read-only. It's important to note that these default rules may not apply to all use cases.
 +
 
 +
Before 10.0.0, the Inaccessible Widget Blocking Service is not enabled by default. Users need to enable it manually.
 +
 
 +
== Enable by Default ==
 +
{{versionSince|10.0.0}} In ZK 10.0.0 and later, this blocking service is enabled by default to enhance security.
 +
 
 +
== How to Disable ==
 +
Since this service blocks all events sent from invisible components. If you have such need, you can disable it.
 +
<source lang='xml'>
 +
<library-property>
 +
    <name>org.zkoss.zkmax.au.IWBS.disable</name>
 +
    <value>true</value>
 +
</library-property>
 +
</source>
 +
 
 +
 
 +
== Limitation ==
 +
This service is an additional filter to improve security but does not replace verifying roles and permissions in your business logic. Always verify access on the server side.
 +
 
 +
 
 +
== Apply the Default Blocking Service==
 +
 
 +
To apply it to the whole application, just specify the following in <code>zk.xml</code> as follows:
  
 
<source lang="xml">
 
<source lang="xml">
Line 25: Line 49:
 
</source>
 
</source>
  
Then, each time a desktop is created, an instance of <tt>InaccessibleWidgetBlockService</tt> is added to the desktop to block the requests from the inaccessible widgets.
+
Then, each time a desktop is created, an instance of <code>InaccessibleWidgetBlockService</code> is added to the desktop to block the requests from the inaccessible widgets.
  
In many cases, you just want to block particular events, not all events. For example, you want to receive <tt>onOpen</tt> when a <tt>menupopup</tt> is going to show up. Then, you can specify a library property called <javadoc>org.zkoss.zk.au.IWBS.events</javadoc> to control the behavior of <javadoc>org.zkoss.zkmax.au.InaccessibleWidgetBlockService</javadoc>. For example,
 
  
<source lang="xml">
 
<library-property>
 
<name>org.zkoss.zkmax.au.IWBS.events</name>
 
<value>onClick,onChange,onSelect</value>
 
</library-property>
 
</source>
 
  
= Implement Your Own Blocking Rule =
+
== Default Blocking Rules==
 +
* Block all events from '''disabled''' and '''invisible''' components
 +
* Block <code>onChange, onChanging, onSelect</code> of a '''read-only''' component
 +
* '''Don't''' block <code>onOpen</code>
 +
<!-- see protected static boolean shallBlockPerComponent(AuRequest request) -->
  
The implementation of <tt>AuService</tt> is straightforward. For example, the following example blocks only <tt>button</tt> and <tt>onClick</tt>:
 
  
<source lang="java">
+
== Supported Components ==
public class MyBlockService implements org.zkoss.zk.au.AuService {
 
public boolean service(AuRequest request, boolean everError) {
 
final Component comp = request.getComponent();
 
return (comp instanceof Button) && "onClick".equals(request.getCommand());
 
//true means block
 
}
 
}
 
</source>
 
 
 
= Supported Components =
 
  
All invisible components would be blocked.
+
All invisible components are blocked.
Some components would be blocked when they are disabled/readonly, as follow.
+
Some components are blocked when they are disabled/read-only, as follows:
  
{| border="2" style="width:50%;"
+
{| class='wikitable'
 
|-
 
|-
 
! style="width:80%"| '''Component'''
 
! style="width:80%"| '''Component'''
Line 100: Line 110:
 
|}
 
|}
  
=Version History=
+
== Specify Events to Block ==
{{LastUpdated}}
+
If you just want to block particular events, not all events. Then, you can specify a list of events in <code>zk.xml</code> like below to control the behavior of <javadoc>org.zkoss.zkmax.au.InaccessibleWidgetBlockService</javadoc>. For example,
{| border='1px' | width="100%"
+
 
! Version !! Date !! Content
+
<source lang="xml">
|-
+
<library-property>
| 8.0.3
+
<name>org.zkoss.zkmax.au.IWBS.events</name>
| 2016/09/21
+
<value>onClick,onChange,onSelect</value>
| Add "supported components" table
+
</library-property>
|-
+
</source>
| &nbsp;
+
 
| &nbsp;
+
= Implement Your Own Blocking Rules =
| &nbsp;
+
If you want to block a request for inaccessible widgets for the whole application or for a particular desktop, you can implement the <javadoc>org.zkoss.zk.au.AuService</javadoc> interface to filter out unwanted requests.
|}
+
The implementation of <code>AuService</code> is straightforward. For example, the following example blocks only <code>onClick</code> of <code>Button</code>:
 +
 
 +
<source lang="java">
 +
public class MyBlockService implements org.zkoss.zk.au.AuService {
 +
public boolean service(AuRequest request, boolean everError) {
 +
final Component comp = request.getComponent();
 +
return (comp instanceof Button) && "onClick".equals(request.getCommand());
 +
//true means block
 +
}
 +
}
 +
</source>
 +
 
 +
 
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 07:14, 18 April 2024


DocumentationZK Developer's ReferenceSecurity TipsBlock Request for Inaccessible Widgets
Block Request for Inaccessible Widgets



Non-existing Components are Safer than Invisible Ones

Users can easily access inaccessible elements (such as disabled or invisible ones) with a browser developer tool. For example, a hostile user can make an invisible button visible and then click it to trigger unexpected actions. Thus, it is recommended not to create an element if it is not supposed to be accessible. For example, the first statement is safer than the second one in the following example:

<button unless="${accessible}"/>
<button visible="${accessible}"/>

Block with InaccessibleWidgetBlockService

Since 5.0.0

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png


ZK provides the `InaccessibleWidgetBlockService` to block events sent from inaccessible widgets with a default set of rules. An inaccessible widget is defined as one that is either disabled, invisible, or read-only. It's important to note that these default rules may not apply to all use cases.

Before 10.0.0, the Inaccessible Widget Blocking Service is not enabled by default. Users need to enable it manually.

Enable by Default

Since 10.0.0 In ZK 10.0.0 and later, this blocking service is enabled by default to enhance security.

How to Disable

Since this service blocks all events sent from invisible components. If you have such need, you can disable it.

<library-property>
    <name>org.zkoss.zkmax.au.IWBS.disable</name>
    <value>true</value>
</library-property>


Limitation

This service is an additional filter to improve security but does not replace verifying roles and permissions in your business logic. Always verify access on the server side.


Apply the Default Blocking Service

To apply it to the whole application, just specify the following in zk.xml as follows:

<listener>
	<listener-class>org.zkoss.zkmax.au.InaccessibleWidgetBlockService$DesktopInit</listener-class>
</listener>

Then, each time a desktop is created, an instance of InaccessibleWidgetBlockService is added to the desktop to block the requests from the inaccessible widgets.


Default Blocking Rules

  • Block all events from disabled and invisible components
  • Block onChange, onChanging, onSelect of a read-only component
  • Don't block onOpen


Supported Components

All invisible components are blocked. Some components are blocked when they are disabled/read-only, as follows:

Component
Button
A
Listbox
Menuitem
Navitem
Textbox
Tree
Intbox
Spinner
Doublebox
Decimalbox
Longbox
Doublespinner
Timepicker
Timebox
Checkbox
Datebox
Combobox
Chosenbox
Selectbox

Specify Events to Block

If you just want to block particular events, not all events. Then, you can specify a list of events in zk.xml like below to control the behavior of InaccessibleWidgetBlockService. For example,

<library-property>
	<name>org.zkoss.zkmax.au.IWBS.events</name>
	<value>onClick,onChange,onSelect</value>
</library-property>

Implement Your Own Blocking Rules

If you want to block a request for inaccessible widgets for the whole application or for a particular desktop, you can implement the AuService interface to filter out unwanted requests. The implementation of AuService is straightforward. For example, the following example blocks only onClick of Button:

public class MyBlockService implements org.zkoss.zk.au.AuService {
	public boolean service(AuRequest request, boolean everError) {
		final Component comp = request.getComponent();
		return (comp instanceof Button) && "onClick".equals(request.getCommand());
			//true means block
	}
}




Last Update : 2024/04/18

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.