Foundations of Security: What Every Programmer Needs to Know / Edition 1

Foundations of Security: What Every Programmer Needs to Know / Edition 1

by Christoph Kern
     
 

View All Available Formats & Editions

ISBN-10: 1590597842

ISBN-13: 2901590597841

Pub. Date: 02/14/2007

Publisher: Apress

Chances are that unless we all learn something about security, the Internet will continue to be a very vulnerable place in which cybercriminals thrive. If you write code that runs on the Web, and you don't know all the material in this book, your code can probably be quite easily hacked. If you do learn all the material in this book, your code will not only be more

Overview

Chances are that unless we all learn something about security, the Internet will continue to be a very vulnerable place in which cybercriminals thrive. If you write code that runs on the Web, and you don't know all the material in this book, your code can probably be quite easily hacked. If you do learn all the material in this book, your code will not only be more robust in the face of attacks, but you will also become more marketable to companies and potential employers because you will know more about how to keep their customers and users safe from cyber-attacks.

This book takes a principled approach to helping you design and implement your applications to be secure from the ground up, and illustrates these principles using running examples of web applications throughout the book. Just as you might use object-oriented design principles to achieve extensibility and code reuse, you need to learn about security design principles, such as the principle of least privilege, fail-safe stance, and securing the weakest link, to achieve security-all of which is covered in this book.

This book does not just focus on merely teaching you "tips" and "tricks" that allow you to "band-aid" the security of your systems. Instead, it illustrates how security principles can be employed to prevent some of the most significant, current-day attack types, such as cross-site scripting (XSS) and SQL injection, as well as more traditional attack types such as buffer overflows. We also cover session and password management, and show you how you can use cryptography to help achieve various security goals. This book is based on the curriculum for the Stanford Center for Professional Development (SCPD)Computer Security Certification. Many programmers and companies have already benefited from the curriculum, and we hope and expect that many more will benefit from this book.

Product Details

ISBN-13:
2901590597841
Publisher:
Apress
Publication date:
02/14/2007
Series:
Expert's Voice Series
Edition description:
2007
Pages:
320

Table of Contents


Foreword     xv
About the Authors     xvii
About the Technical Reviewer     xix
Acknowledgments     xxi
Preface     xxiii
Security Design Principles
Security Goals     3
Security Is Holistic     3
Physical Security     4
Technological Security     4
Policies and Procedures     6
Authentication     7
Something You Know     7
Something You Have     8
Something You Are     10
Final Notes on Authentication     11
Authorization     12
Access Control Lists (ACLs)     13
Access Control Models     14
The Bell-LaPadula Model     15
Confidentiality     17
Message/Data Integrity     18
Accountability     19
Availability     20
Non-repudiation     21
Concepts at Work     22
Secure Systems Design     25
Understanding Threats     25
Defacement     26
Infiltration     26
Phishing     27
Pharming     28
Insider Threats     28
Click Fraud     29
Denial-of-Service (DoS)     29
Data Theft and Data Loss     30
Designing-In Security     30
Windows 98     31
The Internet     31
Turtle Shell Architectures     34
Convenience and Security     35
SimpleWebServer Code Example     35
Hypertext Transfer Protocol (HTTP)     35
Code Walkthrough     36
Security in Software Requirements     44
Specifying Error Handling Requirements     44
Sharing Requirements with Quality Assurance (QA)     46
Handling Internal Errors Securely     47
Including Validation and Fraud Checks     48
Writing Measurable Security Requirements     50
Security or Bust     50
Security by Obscurity     51
Flaws in the Approach     51
SimpleWebServer Obscurity     52
Things to Avoid     55
Open vs. Closed Source     57
A Game of Economics     58
"Good Enough" Security     59
Secure Design Principles     61
The Principle of Least Privilege     61
Defense-in-Depth     63
Prevent, Detect, Contain, and Recover     63
Don't Forget Containment and Recovery     64
Password Security Example     65
Diversity-in-Defense     65
Securing the Weakest Link     66
Weak Passwords     66
People     66
Implementation Vulnerabilities     67
Fail-Safe Stance     67
SimpleWebServer Fail-Safe Example     67
Attempted Fix 1: Checking the File Length     69
Attempted Fix 2: Don't Store the File in Memory     69
Fix: Don't Store the File in Memory, and Impose a Download Limit     70
Secure by Default     71
Simplicity     72
Usability     73
Security Features Do Not Imply Security     74
Exercises for Part 1     77
Secure Programming Techniques
Worms and Other Malware     83
What Is a Worm?     83
An Abridged History of Worms     84
The Morris Worm: What It Did     84
The Morris Worm: What We Learned     85
The Creation of CERT     86
The Code Red Worm     86
The Nimda Worm     87
The Blaster and SQL Slammer Worms     87
More Malware      89
Buffer Overflows     93
Anatomy of a Buffer Overflow     93
A Small Example     94
A More Detailed Example     94
The safe_gets() Function     98
Safe String Libraries     100
Additional Approaches     101
StackGuard     101
Static Analysis Tools     102
Performance     103
Heap-Based Overflows     103
Other Memory Corruption Vulnerabilities     103
Format String Vulnerabilities     104
Integer Overflows     104
Client-State Manipulation     107
Pizza Delivery Web Site Example     108
Attack Scenario     110
Solution 1: Authoritative State Stays at Server     112
Solution 2: Signed State Sent to Client     114
Using HTTP POST Instead of GET     117
Cookies     119
JavaScript     121
SQL Injection     123
Attack Scenario     124
Solutions     130
Why Blacklisting Does Not Work     130
Whitelisting-Based Input Validation     132
Escaping     132
Second Order SQL Injection     133
Prepared Statements and Bind Variables     134
Mitigating the Impact of SQL Injection Attacks     136
Password Security     139
A Strawman Proposal     139
Hashing     141
Offline Dictionary Attacks     143
Salting     144
Online Dictionary Attacks     150
Additional Password Security Techniques     151
Strong Passwords     151
"Honeypot" Passwords     151
Password Filtering     151
Aging Passwords     152
Pronounceable Passwords     152
Limited Login Attempts     152
Artificial Delays     152
Last Login     153
Image Authentication     153
One-Time Passwords     154
Cross-Domain Security in Web Applications     155
Interaction Between Web Pages from Different Domains     156
HTML, JavaScript, and the Same-Origin Policy     156
Possible Interactions of Documents from Different Origins     157
HTTP Request Authentication     159
Lifetime of Cached Cookies and HTTP Authentication Credentials     160
Attack Patterns     161
Cross-Site Request Forgery (XSRF)      162
Cross-Site Script Inclusion (XSSI)     164
Cross-Site Scripting (XSS)     165
Preventing XSRF     169
Inspecting Referer Headers     170
Validation via User-Provided Secret     170
Validation via Action Token     171
Security Analysis of the Action Token Scheme     173
Preventing XSSI     176
Authentication via Action Token     176
Restriction to POST Requests     177
Preventing Resource Access for Cost Reasons     177
Preventing XSS     178
General Considerations     179
Simple Text     180
Tag Attributes (e.g., Form Field Value Attributes)     181
URL Attributes (href and src)     183
Style Attributes     185
Within Style Tags     186
In JavaScript Context     186
JavaScript-Valued Attributes     189
Redirects, Cookies, and Header Injection     190
Filters for "Safe" Subsets of HTML     191
Unspecified Charsets, Browser-Side Charset Guessing, and UTF-7 XSS Attacks     192
Non-HTML Documents and Internet Explorer Content-Type Sniffing     193
Mitigating the Impact of XSS Attacks     194
Exercises for Part 2     197
Introduction to Cryptography
Symmetric Key Cryptography     203
Introduction to Encryption     204
Substitution Ciphers     204
Notation and Terminology     205
Block Ciphers     205
Security by Obscurity: Recap     208
Encrypting More Data     208
AES Code Example     210
Stream Ciphers     217
One-Time Pad     217
RC4     217
Steganography     219
What Is Steganography?     219
Steganography vs. Cryptography     220
Asymmetric Key Cryptography     221
Why Asymmetric Key Cryptography?     221
RSA     223
Elliptic Curve Cryptography (ECC)     223
Symmetric vs. Asymmetric Key Cryptography     224
Certificate Authorities     224
Identity-Based Encryption (IBE)     225
Authentication with Encryption     225
Key Management and Exchange     227
Types of Keys     227
Identity Keys     227
Conversation or Session Keys     227
Integrity Keys     228
Key Generation     228
Random Number Generation     229
The rand() function     230
Random Device Files     230
Random APIs     231
Key (Secret) Storage     231
Keys in Source Code     231
Storing the Key in a File on Disk     233
"Hard to Reach" Places     233
Storing Secrets in External Devices     233
Key Agreement and Exchange     235
Using Asymmetric Keys     236
Diffie-Hellman (DH)     236
MACs and Signatures     239
Secure Hash Functions     239
Message Authentication Codes (MACs)     240
CBC MACs     240
HMAC     241
Signatures     242
Certificates and Certificate Authorities (CAs)     243
Signing and Verifying     246
Registration Authorities (RAs)     246
Web of Trust     247
Attacks Against Hash Functions     247
SSL     247
Server-Authenticated-Only     248
Mutual Authentication     249
Exercises for Part 3     251
Appendixes
Defense-in-Depth: The FLI Model     255
Protecting Against Failure     256
Protecting Against Lies     257
Protecting Against Infiltration     257
Other Techniques     258
Using an FLI-like Model     258
References     258
Source Code Listings     261
References     267
Index     277

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >