11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7: Building Secure Assemblies 165using System.IO;public static string ReadFile(string filename){// Obtain a canonicalized <strong>and</strong> valid filenamestring name = Path.GetFullPath(filename);// Now open the file}As part of the canonicalization process, GetFullPath performs the following checks:●●●●●It checks that the file name does not contain any invalid characters, as defined byPath.InvalidPathChars.It checks that the file name represents a file <strong>and</strong> not an another device type such asa physical drive, a named pipe, a mail slot or a DOS device such as LPT1, COM1,AUX, <strong>and</strong> other devices.It checks that the combined path <strong>and</strong> file name is not too long.It removes redundant characters such as trailing dots.It rejects file names that use the //?/ format.Constrain File I/O Within Your <strong>Application</strong>’s ContextAfter you know you have a valid file system file name, you often need to check that itis valid in your application’s context. For example, you may need to check that it iswithin the directory hierarchy of your application <strong>and</strong> to make sure your code cannotaccess arbitrary files on the file system. For more information about how to use codeaccess security to constrain file I/O, see “File I/O” in Chapter 8, “Code Access<strong>Security</strong> in Practice.”Event LogWhen you write event-logging code, consider the threats of tampering <strong>and</strong>information disclosure. For example, can an attacker retrieve sensitive data byaccessing the event logs? Can an attacker cover tracks by deleting the logs or erasingparticular records?Direct access to the event logs using system administration tools such as the EventViewer is restricted by Windows security. Your main concern should be to ensure thatthe event logging code you write cannot be used by a malicious user forunauthorizedaccess to the event log.

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

Saved successfully!

Ooh no, something went wrong!