In which an exposition of Twelve Web (In)Security Truths begins.

#1 – Software execution is less secure than software design, but running code has more users.

A site you send people to visit is infinitely more useable than the one you describe to people. (Value differs from usability. Before social media flamed you could raise $41 million dollars on a slide deck.) Talk all you want, but eventually someone wants you to deliver.

Sure, you could describe Twitter as a glorified event loop around an echo server. You might even replicate it in a weekend with a few dozen lines of Python or Node.js and an EC2 instance. Just try scaling that napkin design to a few hundred million users while keeping security and privacy controls in place. That’s a testament to implementing a complex design. (Or scaling a simple design if you boil it down to sending and receiving tweets.)

It’s possible to attain impressive security through careful design. A prominent example in cryptography is the “perfect secrecy”1 of the One-Time Pad (OTP). The first OTP appeared in 1882, designed in an era without the codified information theory or cryptanalysis of Claude Shannon and Alan Turing.2 Never the less, its design understood the threats to confidential communications when telegraphs and Morse code carried secrets instead of fiber optics and TCP/IP. Sadly, good designs are sometimes forgotten or their importance unrecognized. The OTP didn’t gain popular usage until its re-invention in 1917, along with a more rigorous proof of its security.

But security also suffers when design becomes implementation. The OTP fails miserably should a pad be reused or is insufficiently random. The pad must be as long as the input to be ciphered. So, if you’re able to securely distribute a pad (remember, the pad must be unknown to the attacker), then why not just distribute the original message? Once someone introduces a shortcut in the name of efficiency or cleverness the security breaks. (Remember the Debian OpenSSL debacle?) This is why it’s important to understand the reasons for a design rather than treat it as a logic table to be condensed like the singularity of a black hole. Otherwise, you might as well use two rounds of ROT13.

Web security has its design successes. Prepared statements are a prime example of a programming pattern that should have relegated SQL injection to the CVE graveyard. Avoiding it is inexcusable. Only devotees of Advanced Persistent Ignorance continue to blithely glue SQL statements together with string concatenation. SQL injection is so well-known (at least by hackers) and studied that a venerable tool like sqlmap has been refining exploitation for over six years. The X-Frame-Options header is another example of design that could dispatch a whole class of vulnerabilities (i.e. clickjacking).

Oh how the Internet loves to re-invent vulns. Whether or not SQL injection is in its death throes, NoSQL injection promises to reanimate its bloated corpse. Herbet West would be proud.

Sometimes software repeats the mistakes of other projects without considering or acknowledging the reasons for those mistakes. The Ruby on Rails Mass Assignment feature is reminiscent of PHP’s register_globals issues. Both PHP and Ruby On Rails are Open Source projects with large communities. It’s unfair to label the entire group as ignorant of security. But the question of priorities has to be considered. Do you have a default stance of high or low security? Do you have language features whose behavior changes based on configuration settings outside the developer’s control, or that always have predictable behavior?

Secure design isn’t always easy. Apache’s reverse proxy/mod_rewrite bug went through a few iterations and several months of discussion before Apache developers arrived at an effective solution. Once again, you might argue that the problem lies with users (i.e. poor rewrite rules that omit a path component) rather than the software. Still, the vuln proved how difficult it is to refine security for complex situations.

HTML injection is another bugbear of web security. (Which makes SQL injection the owlbear?) There’s no equivalent to prepared statements for building HTML on the fly; developers must create solutions for their programming language and web architecture. That doesn’t mean XSS isn’t preventable, prevention just takes more effort and more attention to the context where user-influenced data shows up in a page. Today’s robust JavaScript frameworks help developers avoid many of the XSS problems that arise from haphazard construction of HTML on the server.

There’s hope on the horizon for countering HTML injection with design principles that are tied to HTTP Headers rather than a particular programming language or web framework. The Content Security Policy (CSP) has moved from a Mozilla effort to a standard for all browsers. CSP won’t prevent HTML injection from occurring, but it will diminish its exploitability because developers will be able to give browsers directives that prevent script execution, form submission, and more. CSP even has the helpful design feature of a monitor or enforce mode, thereby easing the transition to a possibly complex policy.

Design is how we send whole groups of vulns to the graveyard. Good security models understand the threats a design counters as well as those it does not. Spend too much time on design and the site will never be implemented. Spend too much time on piecemeal security and you risk blocking obscure exploits rather than fundamental threats.

As the ancient Fremen saying goes, “Truth suffers from too much analysis.”3 So too does design suffer in the face of scrutiny based on unspecific or unreasonable threats. It’s important to question the reasons behind a design and the security claims it makes. Sure, HSTS relies on the frail security of DNS. Yet HSTS is a significant improvement to HTTPS, which in turn is unquestionably better than HTTP. But if you refuse to implement an imperfect solution in favor of preserving the status quo of HTTP then you haven’t done enough consideration of the benefits of encryption.

Nor are security checklists absolute. The httponly attribute prevents no vulnerabilities. It only prevents JavaScript from accessing a cookie. Blindly following the mantra that httponly must exist on all cookies ignores useful designs where JavaScript intentionally reads and writes cookie values. If you’ve put sensitive data into a Local Storage object, then an XSS vuln is going to expose all that tasty data to a hacker who cares little for the cookie’s accessibility.

Design your way to a secure concept, code your way to a secure site. When vulnerabilities arise determine if they’re due to flaws in the design or mistakes in programming. A design that anticipates vulnerabilities (e.g. parameterized queries) should make it easy to fix inevitable bugs. Vulnerabilities that surprise developers should lead to design changes that provide more flexibility for resolving the problem. Inflexibility, whether in design or in code, is dangerous to security. Just like the Bene Gesserit say, “Any road followed precisely to its end leads precisely nowhere.”4

  1. In the sense of Claude Shannon’s “Communication Theory of Secrecy Systems”. 

  2.  As Steven Bellovin notes in his paper, an 1882 codebook contains an amusingly familiar phrase regarding identity questions, “Identity can be established if the party will answer that his or her mother’s maiden name is…“ It seems identity proofs haven’t changed in 130 years! 

  3. Frank Herbert. Dune Messiah. p. 81. 

  4. Frank Herbert. Dune. p. 69.