input validation: the good, the bad and the ugly · action execute... mapping, form, request,...

23
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation OWASP http://www.owasp.org OWASP Europe Conference 2008 Input validation: the Good, the Bad and the Ugly Johan Peeters independent http://secappdev.org http://johanpeeters.com

Upload: others

Post on 27-May-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

Copyright © The OWASP Foundation

Permission is granted to copy, distribute and/or modify this document

under the terms of the OWASP License.

The OWASP Foundation

OWASP

http://www.owasp.org

OWASP Europe Conference 2008

Input validation: the Good, the

Bad and the Ugly

Johan Peeters

independent

http://secappdev.org

http://johanpeeters.com

Page 2: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Motivation

Applications evolve

Page 3: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Aim

Validation architecture

Page 4: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Case study

CRUD securities

Forms for

Create

Search

Update

List search results

View details

Open for modification

Delete

Page 5: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Case study

Web server Application server RDBMS

presentation business logic data

controller

view

model

Page 6: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

JavaScript in the web browser

JSPs with script tags

Custom-built tag library

Populate drop-down boxes

Standard event handlers

JavaScript

<html>

<head>

<script src=“typeCheck.js”/>

</head>

<body>

<form action=“add” method=“post”>

<input type=“submit” value=“Add”/>

<select>

<option value=“bond”>Bond</option>

<option value=“share”>Share</option>

</select>

<input type=“text”

onkeypress=“return isNumeric(event)”

onchange=“return checkSum(event)”/>

</form>

</body>

</html>

Page 7: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Struts on the web tier

view:

.jsp

model

request, response

request, response

ActionServlet

doPost

doGet

...

req

ue

st,

resp

on

se

mapping, request

RequestProcessor

process

...

ActionForm

validate

...

Action

execute

...

mapping, form, request, response

RequestDispatcher

forward

include

...

request, response

controller

Page 8: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

EJBs on the business tier

SecurityFacadeBean

validate

store

...

SecurityDTO

get<property>

set<property>

calculateHash

...

int previousHash

<type> <property>

Page 9: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

RDBMS as data tier

Not NULL

Referential constraints

Columns are typed

Unicity constraints

RDBMS

preparedStatement

Page 10: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Appraisal

Validation does what it is supposed to

Validation code is ugly

Duplication leads to entropy

Maintenance nightmare

Page 11: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Defense in depth

Web server Application server RDBMS

Page 12: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Back to basics

Integrity

Validation serves to

Provide good user experience

Protect against malicious users

Page 13: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Conjecture

Validate to enhance user experience near user

Validate to protect against malicious users near

data

Web server Application server RDBMS

Page 14: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

The front-end revisited

Provide great user experience

Embrace JavaScript

Embrace AJAX

Page 15: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

The back-end revisited

Defend against malicious use

Supplement data types, not NULL, unicity and referential integrity withCheck constraints

Triggers Per statement

– Before

– After

Per row

– Before

– After

Stored procedures

Page 16: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Challenges

Error handling

No big deal: no mercy if you bypass client

Duplication of business logic

Page 17: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Rooting out duplication

If single formalism is used, perhaps the same

code can be called from the different tiers

Expressing the same integrity constraints in different formalisms can bring advantages

Single source distributed over several tiers

Page 18: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Examples of single source to multiple tiers

Ruby on Rails

GWT

Swift

Page 19: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Ruby on Rails code generation

MVC

No business tier

Model is an ActiveRecord instance, its classContains the business logic

maps to a table in RDBMS

generated by a model generator

View is a template with Ruby code

RDBMS endModel generator also generates DDL

Validation in the model, not in the RDBMS

JavaScript generated by helpersPrototype

Script.aculo.us

Page 20: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

GWT compiles Java code to JavaScript

Swing-like APIs for building web user interfaces

Code annotated as ‘client’

Is compiled to JavaScript

Executes in the browser

E.g.

com.johanpeeters.gwt.experiment.client

com.johanpeeters.gwt.experiment.server

Shared client- and server-side validation code is possible

Page 21: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Swift places code on client or server according to security requirements

Annotate variable declarations with security

constraintsint {server -> server; server <- server} secret

int {server -> client; server <- server} tries

Partitions application into

Client

Server

Compiles to client and server GWT packages

GWT compiles client packages to JavaScript

Page 22: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Questions and Comments

Page 23: Input validation: the Good, the Bad and the Ugly · Action execute... mapping, form, request, response RequestDispatcher forward include... request, response controller. ... Shared

OWASP

Thank you!

yo ‘at’ johanpeeters.com

yo ‘at’ secappdev.org