A security flaw rarely comes from a brilliant attack. It comes from an input nobody checked, a permission taken for granted, a key forgotten in a file. Code security is largely a discipline of habits, applied every time you touch something that receives data from outside.
The underlying principle: every input is untrusted
Everything that arrives from outside (forms, parameters, headers, uploaded files, responses from external services, content of databases fed by others) is data that may be hostile. You validate at the boundaries, with explicit rules (type, length, format, allowed values), and reject whatever does not fit. A list of what is allowed is better than a list of what is forbidden.
The areas to guard
Authentication. Passwords are not stored in clear but with an algorithm suited to passwords. Sessions expire, the token does not end up in logs or in addresses. Where possible you use a standard, proven mechanism instead of inventing one.
Authorisation. Who the user is is not enough: you also check what they can do and on which data. The check is done server-side, for every operation, not just by hiding a button. A user must not be able to read another's order by changing a number in an address.
Data. You collect and keep the minimum necessary. Sensitive data is encrypted at rest and in transit. Database queries use parameters, never concatenated text (injection).
Secrets. Keys and passwords are not in the code or in the repository: they are in a secret manager or in environment variables, and they are rotated. If a key ended up in the repository, it must be considered compromised and replaced, not just deleted.
Output. What you show the user is encoded for the context (HTML, URL, command) to prevent execution of content inserted by others.
Dependencies. Every library is somebody else's code that you run with your own permissions. You keep them updated, check known vulnerabilities and add few and justified ones.
External integrations. Responses from an external service are treated as untrusted input; calls have timeouts and error handling.
Logs and errors. Sensitive data is not logged; error messages to the user do not reveal internal details (paths, queries, versions).
Three levels of decision
As in a specification: what you always do (validate inputs, use parameterised queries), what you ask first (add a dependency, change authentication), what you never do (write secrets in code, switch off a check to "try something").
Warning signs
- Input used without validation.
- Access controls only in the interface.
- Queries built by concatenating text.
- Secrets in the repository.
- Error messages with internal details.
- Dependencies never updated.
- Security checks switched off "temporarily".
An example
An endpoint returns an invoice given its number. The interface shows only the user's own invoices, but the endpoint does not check whose the requested invoice is: by changing the number in the address you can read another customer's. The fix is server-side: every request checks that the invoice belongs to the authenticated user. The test: requesting another user's invoice must fail.
When to use it
When handling user input, authentication, data storage or external integrations; when building any function that accepts untrusted data or handles sessions.
This method derives from the open-source agent-skills family by Addy Osmani (MIT licence), rewritten and adapted.
This article is an OIAR skill
What you have just read is the content of a skill from the OIAR catalogue, written for people. Knowledge like this, but richer and deeper, written for the agents, drives the interviews, the analysis and the report inside the platform. Skills are used in OIAR: to try this one on a project of yours you need an account.
security-and-hardeningA method for making code resistant: input validation at the boundaries, authentication, server-side authorisation, protection of data and secrets, dependencies, integrations, logs. Use it when handling untrusted input, sessions, data storage or external services.