Topic: Security

What’s the best way to programmatically edit a pdf in ruby?

I've been doing a good deal of PDF generation in Rails, and had to go through the process of comparing all the available techniques and frameworks in order to find the right solution for my needs.

Its great that there are so many tools out there, but it can be a daunting task to figure out which is best, which will scale, which will continue to grow and improve, and to evaluate the true 'cost' of free vs. commercial.

With all this info finally digested and sorted out,  I was surprised when I got a client request to be able to add a banner to an existing pdf, and from what I can  recall, none of the libraries I know about seem able to do this.  Right now, I'm in the middle of googling the hell out of it, but haven't found my silver-bullet answer yet.  (maybe I should ask jeeves?)

I've done various searches and have come across a few categories of PDF tools:

  1. Wrappers to existing pdf generation tools like fpdf, and iText
  2. PDF Template tools where you build a pdf skeleton file, and bind values to it programmatically
  3. Pure Ruby PDF Generation tools
  4. PDF Readers and inspection tools

I did find a discussion about how this could work on Google Groups between Greg Brown creator of Prawn and Ruport, and James Healey developer of PDF::Reader, but that discussion basically ended with, "Yeah, that would be cool!".

At this point I'm looking into the Origami library which is actually designed for pdf 'security' and testing, and isn't explicitly designed for editing pdfs in this way, but at the moment its the leading candidate in my list.

Have I missed something? Is there an obvious way to do this in ruby/rails that I'm completely overlooking? (I haven't looked very deeply at tools that shell out to the bigger libraries, but I wouldn't rule them out)

The initial requirement was to be able to add a banner/header to an existing PDF, but I can see the complexities of determining how to shift the existing content down without screwing up all the formatting, so I think even being able to insert a coverpage might be a suffcient implementation for now. (Maybe I should be searching for pdf 'merging' instead of editing)

I'll update you with my final solution in an upcoming blog post, and I'll be covering all of the info I've learned on PDF Generation tools for Ruby and Rails  at this year's WindyCityRails Conference on September 12th. Drop by http://windycityrails.org to register. (early registration ends Aug 1st)

Web app security checklist (Braindump)

In Yesterday's post I said I'd put together a quick list of things to think about around web application security. This is by no means an exhaustive list, but its a set of categories and things I start to look at when doing a security assessment on an app.

Web Application Security Checklist
Account management

  • Password management (validation, expiration, previous passwords, etc)
  • Account lockout (number of tries, IP auditing, etc)
  • Role management

Data management

  • Don't Leak sensitive user info (SSNs, account numbers, other identity info) in URLs, cookies, sessions, logs, or printable pages.
  • User Auditing (who changed what, and when)

Browser hacks

  • Cross Site Scripting (XSS)
  • Cross Site Request Forgery (XSRF)

Encrypted transport (make sure Ajax calls are secure)
Encrypted storage (credit cards, ssns, etc)
Server configuration (firewalls, web/app server, db)

I actually have a longer list, but its not formatted/organized very well,  so this is my first cut at sharing it with others.

What other areas do you look at when doing security checks for your web apps?

What tools do you use?

Avoid the last minute security review

lock_med
Photo Credit:
Amagill under Creative Commons Attribution

Security is hard

Security is often an after thought, slated towards the end of a project, or after some big issue has been discovered, but the nature of security functionality, rules, roles, auditing, etc make it hard to layer in to an existing codebase effectively.

Oh, and if the code base isn't sufficiently tested, you're in for a world of hurt.

If you are a developer that was just asked to 'do a quick security check and plug any holes', you are now in the difficult position of managing the expectation that a two-week security review means "we're covered". Be realistic about what you can accomplish, setting out some short-term and long-term goals.

Do More With Less. Start with a research 'Spike'

Instead of pushing for more time to be able to 'cover it all' (even though you have no idea what 'it all' is yet), it might be better to start with a shorter analysis phase, where you detail your findings, identify any trends, and include recommendations for process change. I've found that even the most demanding manager is appreciative and understanding when you ask for a small amount of time in order to produce a better estimate, than to just immediately demand more time without any evidence as to why.

Plan for success

With your analysis and recommendations in hand,
Continue reading »

The Costs of Building Secure Applications

Achieving Balance

'Achieving Balance' by James Jordan

Security is unlike other aspects of software in that it follows a steep value curve: either your system is secure, or it is not. Either it provides its full level of value, or it provides none at all. There is often a tendency to address security up front (even when other aspects of the system are built iteratively). What others sometimes fail to see is how this generates unneeded cost and complexity as the project matures.

Continue reading »

Topics: ,

Firefox Plugin Malware ‘Trojan.PWS.ChromeInject.A’

You knew it had to happen. Malware for Firefox. It happens all the time with IE (so much so that my 17-year-old niece needs a fresh install of Windows every 3 months), but Firefox has been a little less prone -- though not imune -- to malware. See the BitDefender blog post and the Infoworld article which has a bit more detail.

Now Firefox 3 does contain Malware protection, but apparently this plugin is delivered via other system compromises to the filesystem, and apparently Firefox doesn't question already installed plugins.

BTW, the malware registers itself as GreaseMonkey. If you care to, you can follow the Slashdot food fight on this topic.

More as I find out more...

App Security: Throw Out the Org Chart!

Traversing The Org Chart
"Only administrators can add users-- no exceptions! ...except Bob in accounting, but that's because he's covering for Sally. But only until February. And this sort of arrangement might happen again. But most of the time, it won't. I mean.. ninety-nine point nine percent of the time. But there might be exceptions... ".

Sound like a requirement you've heard before? How did you handle it?

In an earlier post, I stated that all security models are idiosyncratic, and that the way you go about designing for security must reflect the nuances and -isms of your organization. You might mistake the form used to express the model (HR records, existing databases, or some XML schema) as your security model, but you risk an uphill battle getting your organization (and I mean the people here, not boxes and circles on an org chart) to accept the result.

All of this has less to do with how we design software and everything to do with the way people organize into groups..
Continue reading »

The Truth About Designing For Security

\
Security is an area of concern where value and cost are often difficult to estimate.  While big mistakes made early on in many areas of an application may prove difficult to correct, this is especially true for security, since its specifications often model a direct reflection of an organizational structure.

And all too often, dysfunctional organizations create dysfunctional security requirements.

It is common knowledge then that a failure to account for security from the start can prove much more costly in the end.  However, over-engineering security needs can require so much effort that your team may not have enough time left over to actually build the very features you are trying to secure.

I find the following two points very useful to keep in mind when participating in discussions concerning security regardless of the application, but especially when working under the assumption that a new application needs the same kind of security model as the old application:

  • All security models are idiosyncratic
  • Never underestimate the cost of being flexible

These two items work as polar opposites of each other:  a flexible system can accommodate many types of organizations, but not without the added cost of training, installation, documentation or maintenance. On the other hand, a static model is cheap to build, but rarely captures the nuances of an organization's structure, particularly as business needs evolve over time.
Continue reading »

SMash – Something Useful from the OpenAjax Alliance?

Openajaxalliancebanner
In the announcement that the OpenAjax Alliance had released OpenAjax Hub 1.0, and would start to work toward 1.1, there was one thing that caught my interest: the news that 1.1 would support secure mashups. Given that proxies and JSONP are both pretty open to abuse by unscrupulous service providers, this was certainly welcome news? So, what exactly does this secure mashup support look like?

The nascent SVN repository at Sourceforge wasn't much help -- mostly just a placeholder for future work. A little digging reveals that the OpenAjax technology will be based on a technique known as 'SMash', developed at IBM for performing secure mashups. I was able to locate a copy of a research paper on SMash (not sure if this is meant to be public, so grab a copy).

Continue reading »

Ajax security surprises: web-aggregators, offline applications and frameworks

Ajaxsecurity

I'm still absorbing the densely packed information from "Ajax Security," the first-rate book by Billy Hoffman and Bryan Sullivan that I recently recommended in these pages. Here, in no particular order, are three of the most surprising lessons imparted by Messrs. Sullivan and Hoffman:

Web aggregators and SSL

This is probably a great big "duh" to some developers, but web aggregators such as iGoogle and NetVibes often compromise the security of otherwise SSL-encrypted web applications when funneling content from them to your personalized homepage:

Now, consider what happens when you use a Gmail widget on an aggregate site like NetVibes. Sharp-eyed readers will notice the URL for NetVibes ... is http://www.netvibes.com. This is not an encrypted connection! NetVibes sends user data in the clear from the aggregate to the user.... NetVibes makes an SSL connection to Gmail, and then NetVibes degrades the level of security by transmitting the data over an unencrypted connection. Our attacker ... can steal the data much more easily now. NetVibes is not providing the same level of security that a user would receive if he accessed Gmail directly. This situation is not unique to NetVibes and Gmail.... At the time of publication, every major aggregate Web site the authors examined downgraded security on data from secure sources. [emphasis theirs]

Continue reading »

Book recommendation: Ajax Security by Hoffman and Sullivan

9780321491930_xs
Reviewers overuse the phrase "required reading," but no other description fits the new book "Ajax Security" (2007, Addison Wesley, 470p). This exhaustive tome from Billy Hoffman and Bryan Sullivan places the specific security concerns of the Ajax programming model in historical perspective. It demonstrates not only new security threats that are unique to Ajax, but established threats that have gained new traction in the Web 2.0 era. It then details both the specific technical solutions and - more importantly - the mindset that are necessary to combat such threats.

Because so many developers have historically overlooked the importance of security, the authors approach their topic for what it is: a remedial subject. They take pains to explain the basic mechanisms by which hackers have exploited insecure web applications over the last decade: cross-site request forgeries, denial of service attacks, cross-site scripting and SQL injection. Then they explain how those mechanisms have changed thanks to the rise of xmlHttpRequest, public APIs, mash-ups and aggregators. If you've ever read a Douglas Crockford rant about the "brokenness" of the web security model and wondered why the guy was such an alarmist, Hoffman and Sullivan are only too happy to provide you with a much-needed wake-up call.

Continue reading »

GWT Security Talk

Billy Hoffman is a wild man when it comes to exploiting JavaScript and HTTP. Watching him twiddle the bits with Firebug was a pleasure. But this talk was more about Ajax security (and really, Browser/Webapp security) than GWT security.

Security is really about the nitty gritty -- dusty corners of technology that can be exploited to subvert an app. As such I might buy his book. It helps to have a big list of holes and tools for exploiting them. But in Billy's own words "these attacks are nothing new. They've been around for years. With Ajax, people are just finding new ways to screw up."

Most of the Ajax security issues are really about having too much state and logic on the client side. GWT, if anything, hides the details (see here and here about leaky business logic) and makes writing code on the client side so much easier (right?) that you are likely to have more state and logic on the server side.

Some good things out of the talk:

- don't make your web services API too granular.
- be careful of control logic DOS attacks, put control logic on server
- use locking on the server to prevent race conditions
- Be careful of third party widgets that can override the logic of other widgets.

Also, using a google gears worker thread, that continues running even after a tab is closed, injecting stuff into the SQLLite DB, you can fill up a 20GB hard drive in under an hour.

One thing I hadn't come across was the technique to make JSON safer, i.e. preventing JSON from being executed via a <script src=""> the way to do that is using the following:

for (;;);

/* rest of JSON message */

Some quotes from Billy:

"SQL injection and cross site scripting is rampant, but exploiting applications is even easier and you can do it with just a browser."

"Ajax provides an increased attack surface."

Technorati Tags: , ,

Topics: ,

>API Keys for Ajax Services

I'm sure not everyone is developing Ajax-based front end sites and applications. There must be someone who is developing XML, JSON and JSONP web services, right? So, if you are going to offer it as a commercial service, and even if you aren't, you still want to be able to control and measure access to it. Something like those Google and Yahoo service API keys, right? I'm sure we've all worked with MD5 and SHA-1 enough to have some ideas about how that would be done, but it helps to have an example to follow.

Well, check out this article over at java.net: Creating and Using API Keys with Java Based Ajax Services. It demonstrates the client and server side pieces to using an API key. Lots of code, and shows how to generate the key from the client web site address and a secret service token. (Note: the example relies on the now outmoded MD5 to generate the token, but that could easily be switched to SHA-1 or some other one-way hash.)

Technorati Tags: , , ,

Google Gears Security Thoughts

The new Google Gears comes with a long set of security warnings and disclaimers. Nitesh Dhanjani over at O'Reilly's ONLamp.com had some initial thoughts about the security of Google Gears:

If I had to pick ..., I’d guess that we are most likely to hear of existing XSS or browser vulnerabilities being abused to steal (or manipulate) Gears databases.

I agree with Nitesh: the attack vectors will remain the same, but the consequences will be much greater. Some folks, such as those working on the Dojo framework, are addressing some of the offline storage issues with encryption:

Right now Dojo offline adds a DES encryption library with functions to encrypt and decrypt. The example used encrypting/decrypting SSNs. He also pointed out that doing this in javascript can be computationally intensive and hasn’t been that feasible before. Right now though using Google Gears worker threads they can encrypt/decrypt in javascript at about 80k/second.

You could also roll your own from  this implementation of AES, RC4, RSA and a number of other algorithms. While this approach solves the stolen laptop problem, it doesn't solve the XSS problem, i.e. as long as you can inject Javacript into a page, you can bypass this security. After all, the plain text has to pass through the sandbox, where it is fair game. In this case, Google Gears just papers over the shortcomings of browsers.

It is possible that WorkerPool could be used to limit the kinds of modifications that are made to the encrypted data:

The WorkerPool behaves like a collection of processes, rather than threads. Workers do not share any execution state.  Changing a variable in one worker has no effect in any other worker.  And created workers do not automatically inherit script code from their parents.

Members of a WorkerPool interact with each other only by sending message strings. Workers can also pass richer data types, by first converting objects to strings using JSON.

We can hide the encryption details in a WorkerPool member and communicate with it via messages. We still pass plain text data through the main browser execution context, but we can at least regulate the access to the encrypted database -- i.e. no bulk downloads or modification.

As a final thought, what's bad for ActiveX is also bad for Google Gears. The fact that the project is open source and thus not a black box, mitigates this criticism only somewhat. To make me comfortable with Google Gears, all of the XSS volnerabilities will have to be closed first.

Technorati Tags: , , , ,

The Problem with JSON

I've been tracking the whole insecure JSON debate over the past couple of weeks with some interest. I've been promoting the use of JSONP for a while, so I thought I'd provide a summary of all of the action and summarize what I myself plan to do.

Rob Yates originally proposed some best practices for the use of JSON in secure applications.

When developing a JSON api that contains data that should not be publically accessible to the world use Approach 1 i.e. return plain JSON.

Joe Walker then started the whole imbroglio with his article showing how to subvert JSON services that return arrays. In Joe's example you redefine the Javascript Array constructor, then call a JSON service using a script tag. He later blogged about how this could be done with objects, as well.

Right now these hacks only work on Firefox, and there are limits to the kind of JSON that can be eval'd outside of an assignment statement, but that is no reason to be complacent about this issue.

This guy tried his hand at defeating the above hack by grabbing a fresh copy of the Array object from an iframe, but in the end concluded that in an arms race between the hacker and the application developer on the client-side, the hacker will always win. As Joe Walker pointed out, "In the end you can't trust the environment that you are sending the data to, so you should only send data to people you trust, and that means having URLs that are not predictable."

A related topic (as pointed out in some of the posts above) is that of Cross-Site Request Forgery (CSRF).

Cross-site request forgery, also known as one click attack or session riding and abbreviated as CSRF (Sea-Surf) or XSRF, is a kind of malicious exploit of websites. Although this type of attack has similarities to cross-site scripting (XSS), cross-site scripting requires the attacker to inject unauthorized code into a website, while cross-site request forgery merely transmits unauthorized commands from a user the website trusts. Compared to XSS, CSRF attacks are not well understood by many web developers and few defense resources are available.

These two methods can be used in concert. For example, the JSON hijacking can be used to lift information such as account numbers, and then CSRF is used to construct a URL that causes some sort of malicious action in the application.

As for what I plan to do in my own secure web application development, it remains pretty consistent with what I did before the advent of Ajax:

  1. Use SSL, obviously.
  2. Don't rely on cookies for authentication and set short timeouts for user sessions. You can require a randomly generated chunk of the path of application url's for each unique session instead.
  3. Make sure that all of your URL's that modify data or have other side effects require POST. This doesn't eliminate risk, as an attacker can use Javascript to launch a form POST, but it does cut down on the opportunistic uses of image and other tags that perform a GET -- reducing the avenues of attack.
  4. Perform referrer checking. Again, this is no panacea, as an attacker can use flash or XHR to subvert this, but it raises the bar a little more and restricts the avenues of attack further.
  5. Use a request token that is dependent on the previous response (SHA-1, etc.) and includes a sequence number. If a request is made that is not valid, the user sessions should be immediately invalidated. (An attacker could theoretically compromise the user's machine so they could defeat even this approach, but at that point I'd have to throw up my hands.)
  6. Detect, log and notify on all suspicious activity.
  7. Use JSON only for publicly available information, i.e. if they can get it by hacking your browser, they can just as easily get it for themselves.

There are limits, however, to what can be done. As long as browsers have security holes and Javascript allows, well, what is allows, there will always be some new avenue of attack for hackers to exploit. (Let's not even get started on viruses and trojan horses on the client).

Further Reading:

You may want to read an article over at IBM on secure mashups which covers additional ground, such as the use of the fragment identifier (http://host/path#fragment). Also, some additional ideas around REST, HTTP Auth, and resetting the Javascript Array object to its original state through delete Array, can be found here.

Finally, the incomparable Bruce Schneier has a blog entry on a paper on JSON Hijacking. Read it and the comments.


Technorati : , , , ,

Topics: ,

Alert: Security Update for Firebug

Joe Hewitt has released a security update to his excellent FireBug Firefox addon.

About an hour ago I received word of a 0-day security exploit that has been discovered and reported. I have just released a new Firebug (version 1.03) with a fix for this bug, and I recommend that everyone install it as soon as possible.

The update has been published to addons.mozilla.org, so you can get it by updating Firebug from the Firefox Add-ons window. Alternatively, you can install the update using the big orange button on the getfirebug.com home page.



Technorati : , , ,

Launch: Pathfinder Newsletter

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email


    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com