21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Solution<br />

Perform data validation at all levels whenever possible. At the very least, make sure<br />

data is filtered on input.<br />

Match constructs that are known to be valid and harmless. Reject anything else.<br />

In addition, be sure to be skeptical about any data coming from a potentially insecure<br />

channel. In a client-server architecture, for example, even if you wrote the client,<br />

the server should never assume it is talking to a trusted client.<br />

Discussion<br />

Applications should not trust any external input. We have often seen situations in<br />

which people had a custom client-server application and the application developer<br />

assumed that, because the client was written in house by trusted, strong coders,<br />

there was nothing to worry about in terms of malicious data being injected.<br />

Those kinds of assumptions lead people to do things that turn out badly, such as<br />

embedding in a client SQLqueries or shell commands that get sent to a server and<br />

executed. In such a scenario, an attacker who is good at reverse engineering can<br />

replace the SQLcode in the client-side binary with malicious SQLcode (perhaps<br />

code that reads private records or deletes important data). The attacker could also<br />

replace the actual client with a handcrafted client.<br />

In many situations, an attacker who does not even have control over the client is nevertheless<br />

able to inject malicious data. For example, he might inject bogus data into<br />

the network stream. Cryptography can sometimes help, but even then, we have seen<br />

situations in which the attacker did not need to send data that decrypted properly to<br />

cause a problem—for example, as a buffer overflow in the portion of an application<br />

that does the decryption.<br />

You can regard input validation as a kind of access control mechanism. For example,<br />

you will generally want to validate that the person on the other end of the connection<br />

has the right credentials to perform the operations that she is requesting.<br />

However, when you’re doing data validation, most often you’ll be worried about<br />

input that might do things that no user is supposed to be able to do.<br />

For example, an access control mechanism might determine whether a user has the<br />

right to use your application to send email. If the user has that privilege, and your<br />

software calls out to the shell to send email (which is generally a bad idea), the user<br />

should not be able to manipulate the data in such a way that he can do anything<br />

other than send mail as intended.<br />

Let’s look at basic rules for proper data validation:<br />

Assume all input is guilty until proven otherwise.<br />

As we said earlier, you should never trust external input that comes from outside<br />

the trusted base. In addition, you should be very skeptical about which<br />

72 | Chapter 3: Input Validation<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!