So you want to write a security book?

Now that I am done with my side project, I wanted to post a note about something that my colleagues frequently ask about: the reality of publishing a security-themed book.


The most important advice I can give is to start with a reality check: writing for technical audiences will probably not make you rich. You will invest somewhere between 200 and 1,000 hours of work over the course of several months. In the next two years, you will likely sell from 1,000 to 50,000 copies (10,000 is pretty good already). Your cut is between $2 and $5 per copy (that's 10-20% of the actual sale price, which in turn is usually around 50% of the cover price); proportionally less if there are multiple authors involved.


The bottom line is that your motivation needs to be something other than money. If there are no quality, up-to-date reference materials in your field of expertise, or if you just have something interesting to share, go for it. If you just want to earn some cash, random consulting gigs would net you more.


If you are still serious about the plan, the next step is choosing between a traditional publisher, and doing all the work yourself. I recommend the former. There are some reputable self-published security books (say, Fyodor's), and if you pursue this route, you will be able to get a slightly larger slice of the revenue pie. That said, you lose some important benefits:



  • You will not get professional editorial feedback. Having an independent sanity check from a person who publishes books for a living helps you set the style and flow of the chapters, and arrange them reasonably. This is harder than it seems. Even the best ideas look bad when presented poorly.


  • You will have to take care of technical illustrations, page layout, indexes, and so on - requiring some talent, and easily adding 50-100 hours of work into the mix.


  • You will have to pay for technical editing and proofreading - or ship the book with typos and grammar errors, which never helps.


  • You will have to invest some effort into marketing, accounting, etc.



If you have a decent proposal, you can approach publishers out of the blue, and pick the one you want to work with; for time being, the demand for infosec authors seems to be higher than the supply. All the publishers will all offer you roughly the same financial terms, but there are some interesting differences in what you will get in return. I know quite a few authors signed up with one of the major publishing houses, and very unhappy about not receiving any editorial attention past the first chapter or two; or not being able to get an illustrator assigned to the project, and having to do the work themselves. In these cases, one has to wonder what the publisher is doing to earn its fees.


So, ask around. For example, in comparison to said publisher, my experiences with
No Starch Press have been very good.

The subtle / deadly problem with CSP

Content Security Policy is a promising new security mechanism deployed in Firefox, and on its way to WebKit. It aims to be many things - but its most important aspect is the ability to restrict the permissible sources of JavaScript code in the policed HTML document. In this capacity, CSP is hoped to greatly mitigate the impact of cross-site scripting flaws: the attacker will need to find not only a markup injection vulnerability, but also gain the ability to host a snippet of malicious JavaScript in one of of the whitelisted locations. Intuitively, that second part is a much more difficult task.


Content Security Policy is sometimes criticized on the grounds of its complexity, potential performance impact, or its somewhat ill-specified scope - but I suspect that its most significant weakness lies elsewhere. The key issue is that the granularity of CSP is limited to SOP origins: that is, you can permit scripts from http://www1.mysite.com:1234/, or perhaps from a wildcard such as *.mysite.com - but you can't be any more precise. I am fairly certain that in a majority of real-world cases, this will undo many of the apparent benefits of the scheme.


To understand the problem, it is important to note that in modern times, almost every single domain (be it mozilla.org or microsoft.com) hosts dozens of largely separate web applications consisting of hundreds of unrelated scripts - quite often including normally inactive components used for testing and debugging needs. In this setting, CSP will prevent the attacker from directly injecting his own code on the vulnerable page - but will still allow him to put the targeted web application in a dangerously inconsistent state, simply by loading select existing scripts in the incorrect context or in an unusual sequence. The history of vulnerabilities in non-web software strongly implies that program state corruption flaws will be exploitable more often than we may be inclined to suspect.


If that possibility is unconvincing, consider another risk: the attacker loading a subresource that is not a genuine script, but could be plausibly mistaken for one. Examples of this include an user-supplied text file, an image with a particular plain-text string inside, or even a seemingly benign XHTML document (thanks to E4X). The authors of CSP eventually noticed this unexpected weakness, and decided to plug the hole by requiring a whitelisted Content-Type for any CSP-controlled scripts - but even this approach may be insufficient. That's because of the exceedingly common practice of offering publicly-reachable JSONP interfaces for which the caller has the ability to specify the name of the callback function, e.g.:



GET /store_locator_api.cgi?zip=90210&callback=myResultParser HTTP/1.0
...

HTTP/1.0 200 OK
Content-Type: application/x-javascript
...
myResultParser({ "store_name": "Spacely Space Sprockets",
"street": ... });


Having such an API anywhere within a CSP-permitted origin is a sudden risk, and may be trivially leveraged by the attacker to call arbitrary functions in the code (perhaps with attacker-dependent parameters, too). Worse yet, if the callback string is not constrained to alphanumerics – after all, until now, there was no compelling reason to do so – specifying callback=alert(1);// will simply bypass CSP right away.


The bottom line is that CSP will require web masters not only to create a sensible policy, but also thoroughly comb every inch of the whitelisted domains for a number of highly counterintuitive but potentially deadly irregularities like this. And that's the tragedy of origin scoping: if people were good at reviewing their sites for subtle issues, we would not be needing XSS defenses to begin with.

Spekulanter som saboterer

Finansmarkedet er som kjent svært effektivt i den forstand at det er ekstremt vanskelig å tjene penger i markedet uten å ta risiko. Det er godt dokumentert at aktiv forvaltning ikke lønner seg. Vår forståelse for hvordan markedet fungerer har imidlertid utviklet seg betydelig siden den banebrytende kapitalverdimodellen (CAPM) kom på begynnelsen av 60-tallet.

CAPM sier at en aksjes avkastning kun avhenger av markedsavkastningen over tid. Vi vet imidlertid at ting som selskapsstørrelse, bokverdi i forhold til markedspris, selskapets investeringer, fjorårets avkastning etc. påvirker gjennomsnittlig avkastning. I det hele tatt øker bare antallet bevis mot kapitalverdimodellene for hvert år som går. 

Når det er vist at en med relativt enkle strategier kan slå indeksen så burde etterspørselen etter for eksempel småselskapene øke inntil prisen er så høy i forhold til utbyttet at fortjenesten forsvinner. Enhver feilprising burde derfor fordunste så snart den blir offentlig kjent, og kapitalverdimodellen fra 60-tallet burde holde.
Akademia er derfor litt i villrede om hva disse avvikene fra standardmodellen skyldes. Det må imidlertid i hovedsak være ett av to: Enten kan det være at mange aksjer rett og slett er feilpriset eller så er meravkastningen kompensasjon for ukjent risiko.  

Dersom bruddene på kapitalverdimodellen rett og slett skyldes feilprising i markedet, så er det dårlig nytt for investorer som ønsker å utnytte det. Man kan rett og slett ikke stole på at markedet skal fortsette å gjøre elementære feil over tid. Det finnes i dag et børshandlet fond for hvert slikt avvik, så det mangler ikke på muligheter til å utnytte dem. Figuren viser da også hvor ustabile et par velkjente strategier kan være. SML-strategien har sågar gitt negativ avkastning i en lengre periode på 90-tallet.

Kilde: Kenneth Frenchs hjemmeside og egne beregninger. Data fra det amerikanske aksjemarkedet (CRSP)
  • SMB viser hvor mye man kan tjene på å vekte seg opp i små selskaper og vekte seg ned i store selskaper.
  • HML viser hvor mye man kan tjene på å vekte seg opp i “undervurderte” selskaper med høy bokverdi i forhold til aksjekurs, og vekte seg ned i “overvurderte” selskaper.
  • Figuren viser ti års glidende gjennomsnitt. 
  • I grafikken i DN ble dessverre HML og SMB byttet om i figuren.


Alternativt er meravkastningen en kompensasjon for en eller annen type risiko. Det kan hende investorer forsøker å holde seg unna små aksjer fordi de anses som mer risikable. Paradokset er at vi ikke finner igjen denne risikoen når vi analyserer aksjene over mange år. 

Det finnes imidlertid en plausibel forklaring på det vi observerer. I 2007 foreslo to av de mest kjente finansøkonomene, Eugene Fama og Kenneth French at feilene med CAPM rett og slett kunne skyldes uenighet mellom investorer. 

La oss tenke oss at det er to grupper investorer. Den ene gruppen består av rasjonelle langsiktige investorer med full informasjon og kompetanse til å prise alle selskapene i økonomien. Den andre gruppen består av spekulanter som ikke vet sitt eget beste og kjøper og selger aksjer i hytt og pine. Prisene på aksjene i en slik økonomi vil da være et vektet gjennomsnitt av hva hver av disse to gruppene verdsetter dem til.  Desto flere utilregnelige spekulanter, desto mer feilprising. 

De som kjenner til spillet “Vil du bli millionær” vet at ett av hjelpemidlene er å spørre publikum. Det viser seg imidlertid at dersom deltakeren eksplisitt ber alle som ikke har peiling om ikke å stemme, så blir publikums svar langt mer presis. Slik fungerer også markedet. Dersom disse investorene innså sin egen begrensning og heller investerte i indeksfond så ville gruppen av forstyrrende spekulanter bli mindre, og markedet ville blitt mer effektivt.

For den store majoriteten av investorer ville det betydd et mer velfungerende marked med mindre feilprising og risiko. En slik verden ville imidlertid vært kjedelig for oss som driver forskning innen dette området, så forhåpentligvis vil utilregnelige spekulanter fortsette å gi oss noe å fylle dagene med også i fremtiden.


Kapitalverdimodellen
(Capital Asset Pricing Model, CAPM)
  • Standardmodellen innen finans utviklet av blant andre Jan Mossin ved NHH.
  • Forteller at avkastning er bestemt av hvor tett aksjen følger markedsindeksen, og bare det.
  • Dersom en aksje for eksempel i gjennomsnitt beveger seg med 2% når indeksen endrer seg med 1% bør avkastningen utover bankrente over tid være dobbelt så stor som markedsavkastningen