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.

There are many other situations where security-critical race conditions occur, particularly<br />

in file access. Basically, every time a condition is explicitly checked, one needs<br />

to make sure that the result cannot have changed by the time that condition is acted<br />

upon.<br />

2.4 Determining Whether a Directory Is Secure<br />

<strong>Problem</strong><br />

Your application needs to store sensitive information on disk, and you want to<br />

ensure that the directory used cannot be modified by any other entity on the system<br />

besides the current user and the administrator. That is, you would like a directory<br />

where you can modify the contents at will, without having to worry about future permission<br />

checks.<br />

Solution<br />

Check the entire directory tree above the one you intend to use for unsafe permissions.<br />

Specifically, you are looking for the ability for users other than the owner and<br />

the superuser (the Administrator account on Windows) to modify the directory. On<br />

Windows, the required directory traversal cannot be done without introducing race<br />

conditions and a significant amount of complex path processing. The best advice we<br />

can offer, therefore, is to consider home directories (typically x:\Documents and Settings\User,<br />

where x is the boot drive and User is the user’s account name) the safest<br />

directories. Never consider using temporary directories to store files that may contain<br />

sensitive data.<br />

Discussion<br />

Storing sensitive data in files requires extra levels of protection to ensure that the<br />

data is not compromised. An often overlooked aspect of protection is ensuring that<br />

the directories that contain files (which, in turn, contain sensitive data) are safe from<br />

modification.<br />

This may appear to be a simple matter of ensuring that the directory is protected<br />

against any other users writing to it, but that is not enough. All the directories in the<br />

path must also be protected against any other users writing to them. This means that<br />

the same user who will own the file containing the sensitive data also owns the directories,<br />

and that the directories are all protected against other users modifying them.<br />

The reason for this is that when a directory is writable by a particular user, that user<br />

is able to rename directories and files that reside within that directory. For example,<br />

suppose that you want to store sensitive data in a file that will be placed into the<br />

Determining Whether a Directory Is Secure | 45<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!