Skip to content

Commit a6c5446

Browse files
committed
Updated reflected/ stored XSS samples
1 parent 04c63c9 commit a6c5446

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

Ch07_XSS/src/main/java/de/dominikschadow/webappsecurity/beans/SearchBean.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,54 @@
2020

2121
import de.dominikschadow.webappsecurity.daos.CustomerDAO;
2222
import de.dominikschadow.webappsecurity.domain.Customer;
23+
import org.apache.commons.lang3.StringUtils;
2324

2425
import javax.faces.bean.ManagedBean;
2526
import javax.faces.bean.RequestScoped;
27+
import javax.faces.context.FacesContext;
2628
import java.util.List;
29+
import java.util.Map;
2730

2831
/**
32+
* Searches customers by the given customer name. The search string can be passed via
33+
* <code>customerName</code> setter method or as a <code>customerName</code> parameter.
2934
*
3035
* @author Dominik Schadow
3136
*/
3237
@ManagedBean(name = "searchBean")
3338
@RequestScoped
3439
public class SearchBean {
35-
private Customer customer;
40+
private String customerName;
3641
private CustomerDAO customerDAO;
3742
private List<Customer> customers;
3843

3944
public SearchBean() {
40-
customer = new Customer();
4145
customerDAO = new CustomerDAO();
4246
}
4347

44-
public Customer getCustomer() {
45-
return customer;
48+
public String getCustomerName() {
49+
return customerName;
4650
}
4751

48-
public void setCustomer(Customer customer) {
49-
this.customer = customer;
52+
public void setCustomerName(String customerName) {
53+
this.customerName = customerName;
5054
}
5155

5256
public List<Customer> getCustomers() {
5357
return customers;
5458
}
5559

5660
public String search() {
57-
customers = customerDAO.findCustomers(customer);
61+
if (StringUtils.isEmpty(customerName)) {
62+
Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
63+
customerName = (String) requestMap.get("customerName");
64+
}
5865

59-
return "/searchCustomer.xhtml";
66+
Customer search = new Customer();
67+
search.setName(customerName);
68+
69+
customers = customerDAO.findCustomers(search);
70+
71+
return "searchCustomer";
6072
}
6173
}

Ch07_XSS/src/main/resources/customerDB.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ INSERT INTO CUSTOMER VALUES(3,'Tricia Trillian McMillan','C',1000,'')
5151
INSERT INTO CUSTOMER VALUES(4,'Zaphod Beeblebrox','D',500,'')
5252
INSERT INTO CUSTOMER VALUES(5,'Marvin','A',100000,'')
5353
INSERT INTO CUSTOMER VALUES(6,'Slartibartfast','D',100,'')
54-
INSERT INTO CUSTOMER VALUES(7,'Stored XSS','X',9999,'<script>alert("Stored XSS Session ID " + document.cookie)</script>')
54+
INSERT INTO CUSTOMER VALUES(7,'Stored XSS','X',9999,'<script>alert("Stored XSS - Session ID: " + document.cookie)</script>')

Ch07_XSS/src/main/webapp/index.xhtml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
33
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4-
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
4+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
5+
xmlns:f="http://java.sun.com/jsf/core">
56
<h:head>
67
<title>Ch07_XSS</title>
78
</h:head>
@@ -21,5 +22,18 @@
2122
</h:form>
2223

2324
<h2>Attacks</h2>
25+
26+
<ul>
27+
<li>Stored XSS</li>
28+
<li>
29+
<h:form>
30+
<h:commandLink action="#{searchBean.search}" value="Relected XSS">
31+
<f:param name="customerName" value="Dummy&lt;script&gt;alert('Reflected XSS - Session ID: ' + document.cookie)&lt;/script&gt;" />
32+
</h:commandLink>
33+
</h:form>
34+
</li>
35+
<li>DOM Based XSS</li>
36+
</ul>
37+
2438
</h:body>
2539
</html>

Ch07_XSS/src/main/webapp/search.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<h:form id="searchCustomers">
1818
<h:panelGrid columns="2">
1919
<h:outputLabel value="Name" for="cName" />
20-
<h:inputText value="#{searchBean.customer.name}" label="Name" id="cName"/>
20+
<h:inputText value="#{searchBean.customerName}" label="Name" id="cName"/>
2121
</h:panelGrid>
2222
<h:commandButton value="Search" action="#{searchBean.search}" styleClass="send-button" />
2323
</h:form>

Ch07_XSS/src/main/webapp/searchCustomer.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<h:link outcome="index" value="Home" /> | <h:link outcome="createCustomer" value="Create Customer" /> | <h:link outcome="showCustomers" value="Show Customers" /> | <h:link outcome="search" value="Search Customer" />
1616
</h:form>
1717

18-
<p>Your search for <strong><h:outputText value="#{searchBean.customer.name}" escape="false"/></strong> returned the following results:</p>
18+
<p>Your search for <strong><h:outputText value="#{searchBean.customerName}" escape="false"/></strong> returned the following results:</p>
1919

2020
<h:form>
2121
<h:dataTable var="customer" value="#{searchBean.customers}">

0 commit comments

Comments
 (0)