Web Application Security & the OWASP Top 10
The OWASP Top 10 is the industry-standard list of the most critical web application security risks. Three of the most common show up constantly in real applications:
SQL injection
When user input is concatenated directly into a SQL query, an attacker can change the query's meaning entirely:
Fix: always use parameterized queries / prepared statements, which send the input separately from the query structure so it can never be interpreted as SQL:
Cross-site scripting (XSS)
XSS happens when an attacker gets their own JavaScript to run in another user's browser, usually by injecting a <script> tag into content that gets rendered without escaping:
Fix: escape user-generated content before rendering it as HTML (most modern frameworks like React do this by default), and use a Content-Security-Policy header to restrict what scripts are allowed to run at all.
Cross-site request forgery (CSRF)
CSRF tricks a logged-in user's browser into submitting a request they didn't intend to make, since browsers automatically attach cookies to requests, a malicious site can make your browser send a request to a site you're logged into.
Fix: require a unique, unpredictable CSRF token on state-changing requests (form submissions, not just GET requests), and set cookies with SameSite=Strict or SameSite=Lax so they aren't sent on cross-site requests.
WARNING
The common thread across all three: never trust user input. Validate it, escape it for the context it's used in (SQL, HTML, a shell command), and use APIs (parameterized queries, templating engines) that make the safe way the easy way.