Protect Websites
Secure websites prevent attackers from modifying pages, stealing information, spreading malware, or taking services offline.
Cybersecurity Topic
Web security protects websites, web applications, servers, databases, users, and online information from attacks, unauthorized access, data theft, and disruption.
Protecting Online Systems
Web security is the practice of protecting websites, web applications, APIs, servers, databases, and users from vulnerabilities and malicious activity.
Secure websites prevent attackers from modifying pages, stealing information, spreading malware, or taking services offline.
Web security protects usernames, passwords, payment information, personal details, and account activity.
Secure coding, encryption, authentication, and access controls help prevent unauthorized access to application data.
Web Application Architecture
A web application usually contains several connected layers. A weakness in any layer may expose the entire application to attack.
The browser displays HTML, CSS, images, and JavaScript while sending requests to web servers.
The web server receives requests and returns website files, application responses, and other content.
Application code processes user input, account actions, business logic, and requests for data.
Databases store user accounts, products, orders, messages, settings, and other application records.
APIs allow websites, applications, servers, and third-party services to exchange information.
Cloud platforms may provide hosting, storage, authentication, databases, and content delivery.
Secure Communication
HTTP transfers website information between browsers and servers. HTTPS adds encryption through TLS, helping protect information from interception and modification.
HTTP traffic is not encrypted. Information may be visible to someone monitoring the network connection.
HTTPS encrypts communication and helps users confirm that they are connected to the expected website.
Common Web Threats
Attackers search for weaknesses in application code, user input handling, authentication, permissions, server configuration, and software components.
SQL injection occurs when unsafe user input is included in a database query. An attacker may read, change, or delete database information.
Cross-site scripting allows malicious JavaScript to run inside another user's browser through an unsafe webpage.
CSRF tricks a signed-in user's browser into sending an unwanted request to a trusted website.
Broken access control allows users to view or change resources that should be restricted.
Weak login controls, insecure passwords, predictable reset links, or poor session management may allow account takeover.
Default settings, exposed files, unnecessary services, detailed error messages, and weak permissions can expose a web application.
Outdated frameworks, plugins, libraries, and server software may contain publicly known vulnerabilities.
Unsafe upload features may allow attackers to place malicious scripts or dangerous files on a server.
SSRF may allow an attacker to force a server to send requests to internal systems or restricted services.
Database Security
SQL injection targets applications that build database queries using untrusted user input. Secure applications use parameterized queries rather than combining input directly with SQL.
Use parameterized queries or prepared statements
Validate and restrict user input
Use database accounts with limited permissions
Do not reveal detailed database errors to users
const query =
"SELECT * FROM users WHERE email = ?";
database.execute(
query,
[userEmail]
);
The user value is handled separately from the SQL command, reducing the risk that it will be treated as executable database code.
Browser-Based Attacks
Cross-site scripting, also called XSS, occurs when untrusted content is inserted into a webpage without being safely handled.
Malicious code is saved inside a database or website and later displayed to other users.
Malicious input is immediately returned in a webpage, often through a link or search request.
Client-side JavaScript changes the webpage using unsafe data without proper validation or encoding.
Encode output before displaying user content
Validate input using allowlists
Use a Content Security Policy
Avoid unsafe DOM functions
Account Protection
Secure authentication verifies user identity, while secure session management protects the user after a successful login.
Passwords should be stored using a strong, salted password-hashing algorithm rather than plain text or reversible encryption.
MFA requires an additional verification method, reducing the risk caused by stolen passwords.
Session cookies should use Secure, HttpOnly, and appropriate SameSite settings.
Sessions should expire after inactivity, logout, password changes, or suspicious activity.
Rate limiting and temporary lockouts can reduce password guessing and automated attacks.
Reset links should be random, temporary, single-use, and delivered through a verified method.
Build Security Into the Code
Secure coding reduces vulnerabilities before an application is deployed and makes future maintenance safer and easier.
Accept only expected data types, formats, lengths, and values.
Encode untrusted content before displaying it inside HTML, JavaScript, CSS, or URLs.
Applications, databases, and users should receive only the permissions they require.
Encrypt sensitive information in transit and at rest where appropriate.
Record useful technical details in protected logs without exposing them to website visitors.
Regularly patch frameworks, libraries, plugins, servers, and development tools.
Use code review, automated scanning, and security testing before deployment.
Browser Security Controls
Security headers tell browsers how to handle website content and can reduce several common attack techniques.
| Security Header | Purpose |
|---|---|
| Content-Security-Policy | Restricts which scripts, styles, images, and other resources may load. |
| Strict-Transport-Security | Tells browsers to use HTTPS for future connections to the website. |
| X-Content-Type-Options | Prevents browsers from guessing a file's content type. |
| Referrer-Policy | Controls how much referral information is shared with other websites. |
| Permissions-Policy | Controls access to browser features such as cameras, microphones, and location. |
| Cross-Origin-Opener-Policy | Helps isolate browsing contexts and reduce certain cross-origin attacks. |
Security Testing Software
Security professionals use specialized tools to inspect requests, test applications, identify vulnerabilities, and monitor website activity.
Web Application Scanner
OWASP ZAP can intercept web traffic and scan applications for common security weaknesses.
Web Testing Platform
Burp Suite provides tools for intercepting requests, modifying traffic, testing input, and analyzing application behavior.
Client-Side Inspection
Developer tools help inspect HTML, CSS, JavaScript, cookies, storage, requests, and browser errors.
Web Server Scanner
Nikto checks web servers for outdated software, unsafe files, configuration problems, and known weaknesses.
Database Injection Testing
sqlmap automates authorized testing for SQL injection vulnerabilities in web applications.
Activity Monitoring
Server logs can reveal failed logins, unusual requests, scanning activity, errors, and attack attempts.
Application-Layer Defense
A Web Application Firewall, or WAF, filters HTTP and HTTPS traffic between users and a web application. It can block suspicious requests before they reach the application server.
Filters malicious requests
Helps reduce SQL injection and XSS attacks
Applies rate limits and access rules
Records suspicious web activity
Website Protection
Website owners and developers should use multiple defensive controls rather than relying on a single security feature.
Protect all pages, logins, forms, APIs, and administrative areas with TLS.
Patch the server, CMS, themes, plugins, frameworks, libraries, and databases.
Use strong passwords, MFA, limited permissions, and protected login pages.
Treat all user-controlled information as untrusted until it has been verified.
Maintain secure backups of files, databases, configurations, and important content.
Review login activity, application errors, server requests, and security alerts.
Perform vulnerability scans, code reviews, configuration checks, and authorized testing.
Review Your Knowledge
HTTPS encrypts information traveling between a browser and a web server and helps verify the identity of the website.
SQL injection occurs when unsafe input changes the meaning of a database query.
Cross-site scripting occurs when malicious script content runs inside another user's browser through an unsafe webpage.
Strong password hashing helps protect stored passwords if an application's database is exposed.
A WAF inspects web requests and may block suspicious traffic before it reaches the web application.
Web Security Summary
Strong web security combines secure coding, encrypted communication, authentication, access control, updates, monitoring, testing, and careful server configuration.