Advanced Web Technology 11) Web Security : ESAPI Dr. E. Benoist - - PowerPoint PPT Presentation

advanced web technology 11 web security esapi
SMART_READER_LITE
LIVE PREVIEW

Advanced Web Technology 11) Web Security : ESAPI Dr. E. Benoist - - PowerPoint PPT Presentation

Berner Fachhochschule, Technik und Informatik Advanced Web Technology 11) Web Security : ESAPI Dr. E. Benoist Fall Semester 2010/2011 Advanced Web Technology 11) Web Security : ESAPI 1 Table of Contents Motivations Problems and


slide-1
SLIDE 1

Berner Fachhochschule, Technik und Informatik

Advanced Web Technology 11) Web Security : ESAPI

  • Dr. E. Benoist

Fall Semester 2010/2011

Advanced Web Technology 11) Web Security : ESAPI 1

slide-2
SLIDE 2

Table of Contents

  • Motivations
  • Problems and Solutions

Decoding / Encoding Untrusted Data Handling Authentication and Identity Enforcing Access Control Intrusion detection

  • Configure ESAPI for your business
  • Conclusion

Advanced Web Technology 11) Web Security : ESAPI 2

slide-3
SLIDE 3

OWASP

◮ The Open Web Application Security Project (OWASP)

  • is a worldwide free and open community focused on improving

the security of application software.

◮ Products developed within OWASP

  • OWASP Top 10 : 10 most present vulnerabilities for web sites
  • Web Goat : a deliberately insecure J2EE web application
  • Web Scarab : framework for analysing applications that

communicate using the HTTP and HTTPS protocols.

  • Application Security Verification Standards (ASVS) : defines

four levels of application-level security verification for Web applications.

◮ ESAPI

  • Enterprise Security API: helps software developers guard

against security-related design and implementation flaws.

Advanced Web Technology 11) Web Security : ESAPI Motivations 3

slide-4
SLIDE 4

Architecture of a Web Application

◮ Presentation Layer

  • Responsible for decoding requests and encoding html responses
  • For us uses JSF
  • Can be a templating system in PHP (Smarty for instance)

◮ Business Layer

  • Responsible for business logic
  • Written in POJO for us
  • Contains PHP commands

◮ Persistence Layer

  • Responsible for transferring objects in DataBase and vice-versa
  • For use a JPA implementation (Hibernate or TopLink for

instance)

  • In PHP the PEAR MDB2 library

◮ DataBase Layer

Advanced Web Technology 11) Web Security : ESAPI Motivations 4

slide-5
SLIDE 5

Security Needs in a Web Application

◮ Presentation Layer

  • Encoding in HTML (against XSS attacks)
  • Verification of authentication for accessing resources
  • Validate the strings as numbers or valid passwords (string or

weak)

  • Encode reference to resource (transform direct to indirect

reference)

◮ Business Layer

  • Rights managements of users on functions
  • Encryption of configuration parameters
  • ◮ Data / Database layer
  • Encode SQL (against SQL injection)
  • Access to resource using an alias (transform indirect to direct

reference)

  • Verify the rights a user has on a specific resource

◮ . . .

Advanced Web Technology 11) Web Security : ESAPI Motivations 5

slide-6
SLIDE 6

Decoding / Encoding Untrusted Data1

1Source: Javadoc documentation of the ESAPI package Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Decoding / Encoding Untrusted Data 6

slide-7
SLIDE 7

Decoding / Encoding Untrusted Data (Cont.)

◮ One should never trust input given by the user

  • It must be first canonicalized using function canonicalize()
  • It reduces a possibly encoded string down to its simplest form.

◮ Work with the simplest string ◮ May be stored encoded

  • In the DataBase using encodeForSQL()
  • In a LDAP server encodeForLDAP or encodeForDN (for

distinguished name).

◮ Encode for the output

  • For use in a HTML document encodeForHTML or

encodeForHTMLAttribute

  • For use in a Javascript program encodeForJavascript

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Decoding / Encoding Untrusted Data 7

slide-8
SLIDE 8

Handling Authentication and Identity

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Handling Authentication and Identity 8

slide-9
SLIDE 9

The Authenticator Interface

◮ defines a set of methods for generating and handling

account credentials and session identifiers.

◮ Application must set current user as soon as possible

  • The value of getCurrentUser() is used in several other

places in this API.

◮ Method for login uses request and or session parameter

to retrieve the user try { User user = ESAPI.authenticator().login(request, response); // continue with authenticated user } catch (AuthenticationException e) { // handle failed authentication (it’s already been logged) }

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Handling Authentication and Identity 9

slide-10
SLIDE 10

The Authenticator Interface (Cont.)

◮ Handle password

  • Can change the password of the current user with

changePassword()

  • Can generate a new strong password

generateStrongPassword()

  • Method verifyPasswordStrength() ensures that the pwd

site-specific complexity requirements, like length or number of character sets.

  • Generate a hash of the password using account name as a salt

hashPassword()

◮ Handles login / logout

  • Get username, password or User in session from request

information in method login()

  • logout()

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Handling Authentication and Identity 10

slide-11
SLIDE 11

Enforcing Access Control

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Enforcing Access Control 11

slide-12
SLIDE 12

Enforcing Access Control

◮ Use the login done by Authenticator ◮ Interface AccessController must be extended according

to firm policy

  • An existing DefaultAccessController class exists
  • Reads its rules out of a configuration file
  • Uses AccessControlRules described in the file

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Enforcing Access Control 12

slide-13
SLIDE 13

AccessController

◮ Each time a resource is accessed, one must “Assert” its

availability try { ESAPI.accessController().assertAuthorized(”ց

→businessFunction”,

runtimeData); // execute BUSINESS FUNCTION } catch (AccessControlException ace) { ... attack in progress }

◮ an attacker can attempt to invoke any business function

  • r access any data in your application.
  • Access control checks in the user interface should be repeated

in both the business logic and data layers.

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Enforcing Access Control 13

slide-14
SLIDE 14

Direct Access Reference

◮ Vulnerability: gives access to internal structure

  • Can be files

www.toto.com/download.do?res=mysecretfile.pdf

  • Can be a database index edit.do?page=123
  • and other types of direct object references

◮ As a rule, developers should not expose their direct

  • bject references as it enables attackers to attempt to

manipulate them.

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Enforcing Access Control 14

slide-15
SLIDE 15

AccessReferenceMap

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Enforcing Access Control 15

slide-16
SLIDE 16

AccessReferenceMap

◮ Indirect references are handled as strings, to facilitate

their use in HTML

◮ When a reference is sent to the browser

  • Internal reference is stored in the map,
  • the indirect reference is sent to the browser
  • it is random generated

◮ When a reference is received from the browser

  • The indirect reference is received
  • It is converted back to a direct reference using the map.

◮ If per-user AccessReferenceMaps are used, then request

forgery (CSRF) attacks will also be prevented.

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Enforcing Access Control 16

slide-17
SLIDE 17

AccessReferenceMap (Cont.)

◮ Example of use

Set fileSet = new HashSet(); fileSet.addAll(...); // add direct references (e.g. File objects) AccessReferenceMap map = new AccessReferenceMap( fileSet )ց

→;

// store the map somewhere safe − like the session! String indRef = map.getIndirectReference( file1 ); String href = ”http://www.aspectsecurity.com/esapi?file=” + ց

→indRef );

... // if the indirect reference doesn’t exist, it’s likely an attack // getDirectReference throws an AccessControlException // you should handle as appropriate String indref = request.getParameter( ”file” ); File file = (File)map.getDirectReference( indref );

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Enforcing Access Control 17

slide-18
SLIDE 18

Intrusion Detection

◮ Based on two classes

  • Logger charged to write all the information gathered in the

application

  • IntrusionDetector that “analyses” the values gathered and

reacts according to given “rules”.

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Intrusion detection 18

slide-19
SLIDE 19

Logger

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Intrusion detection 19

slide-20
SLIDE 20

Logger (Cont.)

◮ The Logger interface defines a set of methods that can

be used to log security events.

hierarchy of logging levels

  • Can be configured at runtime level
  • All events bellow a the current threshold are discarded.
  • Levels are :fatal (highest value), error, warning, info, debug,

trace (lowest value)

  • ◮ Loggers must fulfil the following requirements
  • Ensure that HTML characters are encoded (for persons looking

at stats in a browser)

  • Encode and CLRF in order to prevent log injection attacks.
  • Record for each event : the identity of the user, the description
  • f the event, success/failure of the event, security level, IP

address, a time stamp

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Intrusion detection 20

slide-21
SLIDE 21

IntrusionDetector

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Intrusion detection 21

slide-22
SLIDE 22

IntrusionDetector (Cont.)

◮ Track security relevant events and identify attack

behavior.

◮ The interface is currently designed to accept exceptions

as well as custom events.

◮ Implemented in the DefaultIntrusionDetector class

  • This implementation monitors EnterpriseSecurityExceptions to

see if any user exceeds a configurable threshold in a configurable time period.

  • For instance, if a user exceeds 10 input validation issues in a 1

minute period.

  • Or if there are more than 3 authentication problems in a 10

second period.

◮ More complex implementation are possible

Advanced Web Technology 11) Web Security : ESAPI Problems and Solutions: Intrusion detection 22

slide-23
SLIDE 23

Configure ESAPI for your business

◮ Default implementation can be configured

  • Use config files for defining users and roles, such as business

rules

  • Very generic and simplified
  • Needs to be extended

◮ Develop your own implementation of Interfaces ◮ Need to integrate the new classes in the framework

  • Done using “(pseudo)-singleton pattern” or “(pseudo)-Factory

Pattern”

Advanced Web Technology 11) Web Security : ESAPI Configure ESAPI for your business 23

slide-24
SLIDE 24

Pseudo-Singleton Pattern

(uses only static methods) myauthenticator = new MyAuthenticator(); ESAPI.setAuthenticator(myauthenticator); //register with ց

→locator class

authenticator = ESAPI.getAuthenticator(); authenticator.login(...); //use your implementation

Advanced Web Technology 11) Web Security : ESAPI Configure ESAPI for your business 24

slide-25
SLIDE 25

Change the instances

◮ At runtime change the instance used in the ◮ The instance of class ESAPI contains the default values

/ changed values

Advanced Web Technology 11) Web Security : ESAPI Configure ESAPI for your business 25

slide-26
SLIDE 26

Conclusion

◮ ESAPI groups all the security items in one place

  • Easyer to maintain than code in all the application

◮ ESAPI has been tested and developed by security

specialists

  • Never reinvent the wheel
  • Amateurism in security is no security

◮ ESAPI can easily be tailored for your business needs

  • Implement the interfaces
  • Replace the default implementation in the ESAPI class (using

set methods).

Advanced Web Technology 11) Web Security : ESAPI Conclusion 26

slide-27
SLIDE 27

References

◮ The ESAPI Toolkit web pages http://www.owasp.org ◮ OWASP Javadoc of ESAPI http://owasp-esapi-java.

googlecode.com/svn/trunk_doc/2.0-rc4/index.html

Advanced Web Technology 11) Web Security : ESAPI Conclusion 27