defeating xss and xsrf with jsf frameworks€¦ · some tags were not rendering escape=true by...

24
Defeating XSS and XSRF with JSF Frameworks

Upload: others

Post on 25-May-2020

9 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Defeating XSS and XSRF with JSF Frameworks

Page 2: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

About Me

Steve Wolf Vice President, Application Security

AsTech Consulting, Inc. [email protected] www.astechconsulting.com OWASP Chapter Lead – Sacramento, CA [email protected] www.linkedin.com/in/swolf530/

Hosted by OWASP & the NYC Chapter

Page 3: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Oracle/Java Reference Implementation

Apache MyFaces Family

Other Third Party

Build your own

JSF Based Frameworks

Page 4: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Non-persistent XSS

Persistent XSS

Hacker Favorite

Cross Site Scripting

Page 5: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Validate ALL User Input

Context Appropriate Encoding

Protect the Cookies

Preventing Cross Site Scripting

Page 6: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Validation Frameworks

Context Appropriate Encoding

Anti-Samy Input Filters

Web Application Firewalls

JSF Based Frameworks

Page 7: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

JSF 2.2 Server Side Validation

Pre-defined Validation Mechanisms

Custom Validators

JSF Validation Framework

Page 8: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

LongRange Validator

<h:inputText id=“num1" value="#{myDataBean.num1}">

<f:validateLongRange minimum="10" maximum="133" />

</h:inputText>

<h:message for=“num1" style="color:red" /><br/>

Hosted by OWASP & the NYC Chapter

Pre-defined Validators

Page 9: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Other Pre-defined Validators LengthValidator <f:validateLength minimum="5" maximum="10" />

DoubleRangeValidator <f:validateDoubleRange minimum="10.11" maximum="1000.11”/>

RegexValidator <f:validateRegex pattern="((?=.*[a-z])(?=.*[A-Z]))" />

RequiredValidator <f:validateRequired />

Date Time Validator <f:convertDateTime pattern="d-M-yyy"/>

Page 10: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Validator Class Public class EmailValidator implements Validator {

public void validate(FacesContext context, UIComponent

component, Object value) throws ValidatorException {

matcher = "^[_A-Za-z0-9-]+(\\." +

"[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*"

+ "(\\.[A-Za-z]{2,})$"; if(!matcher.matches()){

FacesMessage msg = new FacesMessage("E-mail validation

failed.", "Invalid E-mail format.");

msg.setSeverity(FacesMessage.SEVERITY_ERROR);

throw new ValidatorException(msg);

}

}

}

Hosted by OWASP & the NYC Chapter

Custom Validators

Page 11: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Info.xhtml <h:panelGrid columns="3">

Enter your email :

<h:inputText id="email" value="#{user.email}"

size="20" required="true" label="Email Address">

<f:validator

validatorId="com.myvalidators.EmailValidator" />

</h:inputText>

<h:message for="email" style="color:red" />

</h:panelGrid>

Hosted by OWASP & the NYC Chapter

Custom Validators

Page 12: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Output Encoding

JSF 1.1 Literal text output <h:outputText value="#{user.name}" />

JSF 2.0 Literal text output using EL #{user.name}

Encoding turned off <h:outputText value="#{user.name}" escape="false" />

Page 13: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Another Technique

Jboss SeamTextParser <s:formattedText value=“<b>#{user.name}</b>” />

Page 14: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Some Early Flaws Select Items Renderer <f:selectItems value=“#{bean.selectItems}” var="obj" itemValue="#{obj}" itemLabel="#{obj.name}"/>

JSF Version 1.2 before 1.2_08 Some tags were not rendering escape=true by default.

Websphere JSF Widget Library before 7.0.0.10 TreeControl and ResourceServlet allowing XSS.

GlassFish Admin Console 2.1 Injection via query string on some pages.

Apache MyFaces Tomhawk before 1.1.6 Injections in autoscroll parameter.

Page 15: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Tricks the Browser into Sending Requests

Susceptible Pages are those that Alter Data

Inherits Identity and Privileges of the Victim

Usually Initiated through Fiche or XSS

Cross Site Request Forgery

Page 16: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Full Protection in JSF 2.2

Some earlier JSF based Frameworks

Post vs. Get

Protecting the View State

Cross Site Request Forgery

Page 17: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Protecting a Postback Request

Post is always Protected

Non-Postback Require Config

Page 18: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

faces-config.xml <protected-views>

<url-pattern>my_protected_page.xhtml</url-pattern> </protected-views>

Hosted by OWASP & the NYC Chapter

Protecting a non-Postback Request

Page 19: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

URL when Calling the Protected Page http://localhost/faces/my_protected_page.xhtml?javax.faces.Token=98791798361565472309342

Hosted by OWASP & the NYC Chapter

Protecting a non-Postback Request

Page 20: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

web.xml <env-entry>

<env-entry-name> com.sun.faces.ClientStateSavingPassword

</env-entry-name>

<env-entry-type>java.lang.String</env-entry-type>

<env-entry-value>MY_PASSWORD</env-entry-value>

</env-entry>

Hosted by OWASP & the NYC Chapter

Using JSF 2.2 Built-in Protection

Page 21: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

web.xml <context-param>

<param-name>org.apache.myfaces.USE_ENCRYPTION</param-name>

<param-value>true</param-value>

</context-param>

<context-param>

<param-name>org.apache.myfaces.ALGORITHM</param-name>

<param-value>AES</param-value>

</context-param>

Hosted by OWASP & the NYC Chapter

Encrypting MyFaces Viewstate

Page 22: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Be Informed About the Implementation

Implementations Differ

Doc is Not always Good

Unit Test your Implementation

Corporate Standards

Page 23: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Hosted by OWASP & the NYC Chapter

Wrap-up

JSF Validation Framework

Output Encoding

Protect the View State

Page 24: Defeating XSS and XSRF with JSF Frameworks€¦ · Some tags were not rendering escape=true by default. Websphere JSF Widget Library before 7.0.0.10 . TreeControl and ResourceServlet

Defeating XSS and XSRF with JSF Steve Wolf Vice President, Application Security

AsTech Consulting, Inc. [email protected] www.astechconsulting.com OWASP Chapter Lead – Sacramento, CA [email protected] www.linkedin.com/in/swolf530/

Hosted by OWASP & the NYC Chapter