Input Validation Attacks: When Software Accepts the Wrong Data
A shopping app shouldn't accept an order for minus three items. Input validation attacks try to exploit weaknesses in how software checks and handles supplied data, from impossible quantities to text that changes what a program does.
Input validation means checking that data meets the application's rules before using it. Those checks matter, but safe handling also depends on where the data goes next.
Define what the field can accept
For a hypothetical booking service, the rules might include:
| Field | A useful check |
|---|---|
| Number of tickets | A whole number from 1 to 10 |
| Booking dates | Valid dates, with the end after the start |
| Event choice | One of the events the service actually offers |
| Customer name | A reasonable length, while allowing legitimate punctuation and writing systems |
The software-security nonprofit OWASP recommends checking both format and meaning. A value can be a correctly written number and still be an impossible quantity.
Rules should fit each field. Removing every apostrophe would reject real names without solving the problem of safely handling those names.
The browser isn't the final checkpoint
A form can show a helpful error before someone submits it. But an attacker can send a request without following that form's restrictions.
The server—the computer or program handling the request—must enforce the rules too. Mozilla's form-validation guide explains why browser checks alone aren't a security boundary.
Data from another service or a previously saved record also needs appropriate checks when an application uses it. Being stored already doesn't establish that it meets today's rules.
- Learn to find the flaws in a web app before someone else does.
- Understand injection, broken logins and logic bugs well enough to fix them.
- Build the skills that web security jobs ask for.
When data becomes an instruction
Injection happens when supplied data is interpreted as part of a command or program. Three common forms need different defenses.
SQL injection changes a database request
SQL, short for Structured Query Language, is used to work with databases: organized collections of records. SQL injection can occur when an app joins supplied text directly into a database instruction, allowing that text to change the instruction's meaning.
OWASP recommends parameterized queries, which keep the instruction's structure separate from supplied values. A name is then handled as a value to look up, rather than added as new instruction text.
SQL injection may expose or change records. The damage depends on the database and the application's permissions; it doesn't automatically give an attacker control of every system.
Cross-site scripting reaches another person's browser
Cross-site scripting, usually shortened to XSS, occurs when an application puts untrusted data into a page in a way that lets the browser treat it as code. A submitted comment might become instructions that run when someone views the page.
XSS defenses include output encoding: representing text safely for the particular place it's displayed. If a service deliberately allows users to submit formatted page content, it also needs a suitable sanitizer to remove unsafe features.
Checking a comment's length doesn't provide either protection.
How One Line of Text Can Hack a Website
Command injection reaches the operating system
The operating system manages a computer's programs and resources. Command injection occurs when supplied data changes a command the application asks that system to run.
For example, a filename passed unsafely into a system command could affect more than the intended file operation. OWASP's preferred defense is to use suitable built-in programming functions—ready-made operations developers can call—instead of constructing system commands from input.
Valid data still needs permission
A real customer number in the correct format doesn't give a user permission to view that customer's records. Authorization—the decision about what someone may access—is a separate check.
Good validation answers whether a value is acceptable. The application must also establish whether the action is allowed and handle the value safely wherever it's used.
SQL Injection: When Data Starts Giving the Database Orders

Cross-Site Scripting: When a Webpage Treats Text as Instructions

Buffer Overflow: How a Memory Mistake Becomes an Attack

QUOTE:
"Amateurs hack systems, professionals hack people."
