bastion

Introduction to Web Application Security

Build this skill

Decide which checks must run on the server by drawing the trust boundary between a user's device and the application.

The quantity limit that lived only on the phone

Rohan Iyer, Tulsi Health's app developer, added a sensible rule: nobody may order more than 10 strips of a prescription-only sleeping tablet in one order. He built it into the app screen, so typing 11 turns the box red and greys out the Order button. At the next review Neha Kulkarni, the IT and security lead, asked one question: "Where else is this checked?" The answer was nowhere, and that answer is a security hole. Application security is the work of designing, building and testing software so that it does only what it is meant to do, even when someone deliberately uses it in ways nobody intended.

Why applications must defend themselves

Many security controls sit around a system, like the walls and gate around a housing society. A firewall, for example, is a filter that blocks network traffic that has no business reaching a server. But a web application exists to accept visitors: its order form, login page and search box must be open to anyone on the internet, so the firewall waves those requests through. An attacker who uses the order form is walking in through the front door that the business opened on purpose.

So the application has to protect itself. A bank has a guard at the gate, yet the cashier still checks the signature on every cheque, because the guard cannot know whether a cheque is genuine. An application vulnerability is a weakness in an app's design or code that lets someone make it do something it should not, such as show another customer's orders, accept a price of ₹1, or let a stranger act as a logged-in user.

App weaknessesthe app does what itshould notinputInjectiontyped text runs as acommandpermissionsBroken accesssees others' ordersidentityWeak sessionsa login can be stolendesignTrusting the clientprice or limit set byphone

Most application weaknesses come from a handful of patterns. Each one is a way the app believes or obeys something it should have checked.

Here is what each kind would look like at Tulsi Health. With injection, text typed into a form is treated as part of an instruction instead of as plain information. With broken access control, changing the order number in a link from 4521 to 4522 shows a stranger's prescription, because the app never asks whether that order belongs to you. With weak sessions, the proof that you logged in can be copied or guessed. And when an app trusts the client, it accepts the price, discount or limit that the customer's own phone sends, which is exactly Rohan's problem.

Client side and server side

In web security the customer's phone or browser is called the client: the device that asks for things. Code that runs there is client-side code, and code that runs on Tulsi Health's servers is server-side code. The client belongs to the customer, who can inspect it, change it, or skip it entirely by sending requests with a different tool. Imagine a bank deposit slip you fill in at home: you can write any amount you like on it, and the bank only trusts the amount after the cashier counts the cash.

Client-side checks are still worth having. They give instant, friendly feedback, catch honest typing mistakes, and save the customer a wasted trip to the server. But they are a convenience, never a protection. Every check that matters for safety, money or privacy must also run on the server, where the customer cannot reach it.

Client-side checksRun on the customer's phoneInstant, friendly feedbackCan be changed or skippedA convenience, not protectionServer-side checksRun on Tulsi Health's serversSee every request, app or notCustomers cannot change themThe real protection

Keep the friendly check on the phone if you like, but make the server repeat every check that matters.

The same goes for any value the client sends that the server could work out for itself. If the order request carries the price, someone can change ₹450 to ₹1 before it leaves their phone. The server should ignore any price in the request and look it up in its own price list, just as a shopkeeper reads the price from his own rate card rather than from the customer's note.

Trust boundaries

A trust boundary is the line where information passes from a place you do not control to a place you do. Everything that crosses the line must be checked before it is used, however harmless it looks. The pharmacy counter at Kothrud is a trust boundary. A customer may hand Farida Shaikh any slip of paper, but she checks the doctor's name, the date and the dose before any medicine leaves the shelf, and a neatly printed slip gets the same check as a scrawled one.

User's side: not under your control Tulsi Health's side Medicine Sleep tablets (Rx) Qty 50 Price ₹1 Anyone can change what their own phone sends app checks here can be skipped TRUST BOUNDARY ? every request is checked here Server Server's own checks ✕ Qty over 10 ✕ Needs prescription ✓ Price from own list ₹450, not ₹1 Database Only checked data gets in

The phone can send anything. The server treats every request that crosses the boundary as unchecked, and lets only data that passes its own rules reach the database.

A web application has several boundaries, not just one. The obvious one is between customers' phones and the server. Another is between the server and outside services: a message from a phone saying "payment done" should never be believed until the server has confirmed it with the payment gateway directly. Uploaded files, links that people follow, and data arriving from other companies' systems all cross a boundary too.

Practise drawing the boundary below. For each piece of information, decide whether it comes from the user's side, so the server must check it, or is something the server already holds and controls.

Designing applications to be secure

Checking at the boundary is one habit of secure application design: planning for misuse from the first sketch, rather than patching holes after launch. A few habits catch most problems, and they cost little when they are part of the design from the start.

Habit What it means at Tulsi Health
Never trust the client Repeat every limit, price and permission check on the server
Deny by default A new staff screen is closed to everyone until roles are given access
Least privilege The app's database account can add orders, but cannot delete tables
Defence in depth Server checks, a careful database account and monitoring, so one mistake is not fatal
Fail safely On an error, refuse the action and show a plain message, not internal details

Rohan now has to fix the quantity limit properly. Choose the change that actually closes the hole.

Follow your curiosity.

↑ ↓ to explore · Enter to open · Escape to close