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

Paperback (Print)
Buy New
Buy New from
Used and New from Other Sellers
Used and New from Other Sellers
from $1.99
Usually ships in 1-2 business days
(Save 95%)
Other sellers (Paperback)
  • All (19) from $1.99   
  • New (8) from $24.94   
  • Used (11) from $1.99   


Foundations of Security: What Every Programmer Needs to Know teaches new and current software professionals state-of-the-art software security design principles, methodology, and concrete programming techniques they need to build secure software systems. Once you're enabled with the techniques covered in this book, you can start to alleviate some of the inherent vulnerabilities that make today's software so susceptible to attack. The book uses web servers and web applications as running examples throughout the book.

For the past few years, the Internet has had a "wild, wild west" flavor to it. Credit card numbers are stolen in massive numbers. Commercial web sites have been shut down by Internet worms. Poor privacy practices come to light and cause great embarrassment to the corporations behind them. All these security-related issues contribute at least to a lack of trust and loss of goodwill. Often there is a monetary cost as well, as companies scramble to clean up the mess when they get spotlighted by poor security practices.

It takes time to build trust with users, and trust is hard to win back. Security vulnerabilities get in the way of that trust. Foundations of Security: What Every Programmer Needs To Know helps you manage risk due to insecure code and build trust with users by showing how to write code to prevent, detect, and contain attacks.

  • The lead author co-founded the Stanford Center for Professional Development Computer Security Certification.
  • This book teaches you how to be more vigilant and develop a sixth sense for identifying and eliminating potential security vulnerabilities.
  • You'll receive hands-on code examples for a deep and practical understanding of security.
  • You'll learn enough about security to get the job done.

Table of Contents

  1. Security Goals
  2. Secure Systems Design
  3. Secure Design Principles
  4. Exercises for Part 1
  5. Worms and Other Malware
  6. Buffer Overflows
  7. Client-State Manipulation
  8. SQL Injection
  9. Password Security
  10. Cross-Domain Security in Web Applications
  11. Exercises for Part 2
  12. Symmetric Key Cryptography
  13. Asymmetric Key Cryptography
  14. Key Management and Exchange
  15. MACs and Signatures
  16. Exercises for Part 3
Read More Show Less

Product Details

  • ISBN-13: 9781590597842
  • Publisher: Apress
  • Publication date: 2/15/2007
  • Series: Expert's Voice Series
  • Edition description: 2007
  • Edition number: 1
  • Pages: 320
  • Sales rank: 831,339
  • Product dimensions: 6.90 (w) x 9.10 (h) x 0.90 (d)

Meet the Author

Christoph Kern is an information security engineer at Google and was previously a senior security architect at Yodlee, a provider of technology solutions to the financial services industry. He has extensive experience in performing security design reviews and code audits, designing and developing secure applications, and helping product managers and software engineers effectively mitigate security risks in their software products.

Anita Kesavan is a freelance writer and received her master's in fine arts in creative writing from Sarah Lawrence College, New York. She also holds a bachelor's in English from Illinois-Wesleyan University. She specializes in communicating complex technical ideas in simple, easy-to-understand language.

Neil Daswani has served in a variety of research, development, teaching, and managerial roles at Stanford University, DoCoMo USA Labs, Yodlee, and Bellcore (now Telcordia Technologies). His areas of expertise include security, wireless data technology, and peer-to-peer systems. He has published extensively in these areas, frequently gives talks at industry and academic conferences, and has been granted several U.S. patents. He received a Ph.D. and a master's in computer science from Stanford University, and he currently works for Google. He earned a bachelor's in computer science with honors with distinction from Columbia University.

Read More Show Less

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
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
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)