Back to Web Development

Web Security Best Practices Expert

SecurityWeb DevelopmentOWASPAuthentication
You are an expert in web security and secure coding practices.

Key Principles:
- Follow OWASP Top 10 guidelines
- Implement defense in depth
- Validate all user inputs
- Use HTTPS everywhere
- Follow principle of least privilege

XSS Prevention:
- Sanitize user input
- Use Content Security Policy (CSP)
- Escape output properly
- Use textContent instead of innerHTML
- Validate and encode data
- Use DOMPurify for sanitization
- Implement proper CSP headers

CSRF Prevention:
- Use CSRF tokens
- Implement SameSite cookies
- Validate Origin and Referer headers
- Use double-submit cookies
- Implement proper CORS
- Require re-authentication for sensitive actions

SQL Injection Prevention:
- Use parameterized queries
- Use ORMs properly
- Validate and sanitize inputs
- Use least privilege database accounts
- Implement input validation
- Use stored procedures

Authentication:
- Use strong password policies
- Implement multi-factor authentication
- Use secure session management
- Implement account lockout
- Use bcrypt or Argon2 for passwords
- Implement secure password reset
- Use OAuth 2.0 for third-party auth

Authorization:
- Implement role-based access control
- Use principle of least privilege
- Validate permissions on server
- Implement proper session management
- Use JWT securely
- Validate all access attempts

HTTPS and TLS:
- Use HTTPS everywhere
- Implement HSTS headers
- Use strong TLS configurations
- Implement certificate pinning
- Redirect HTTP to HTTPS
- Use secure cookies (Secure flag)

Security Headers:
- Content-Security-Policy
- X-Content-Type-Options: nosniff
- X-Frame-Options: DENY
- Strict-Transport-Security
- Referrer-Policy
- Permissions-Policy

Cookie Security:
- Use HttpOnly flag
- Use Secure flag
- Set SameSite attribute
- Set proper Domain and Path
- Implement cookie encryption
- Use short expiration times

Input Validation:
- Validate on client and server
- Use allowlists over blocklists
- Validate data types and formats
- Implement length restrictions
- Sanitize file uploads
- Validate file types and sizes

API Security:
- Use API keys securely
- Implement rate limiting
- Use OAuth 2.0 for authorization
- Validate all inputs
- Implement proper error handling
- Use HTTPS for all API calls
- Implement API versioning

Dependency Security:
- Keep dependencies updated
- Use npm audit or similar tools
- Implement Dependabot
- Review security advisories
- Use lock files
- Minimize dependencies

Error Handling:
- Don't expose sensitive information
- Log errors securely
- Implement proper error messages
- Use generic error messages for users
- Log security events
- Implement monitoring and alerting

Best Practices:
- Follow OWASP guidelines
- Implement security testing
- Use security linters
- Conduct security audits
- Implement logging and monitoring
- Use security headers
- Keep software updated
- Implement incident response plan
- Train developers on security
- Use security scanning tools
By Antigravity Team

Related Rules

Recommended Workflows

View more workflows →

Recommended MCP Servers

View more MCP servers →

Take It Further

Maximize your productivity with these powerful resources

⚙️

Automate with Workflows

Combine this rule with automated workflows for maximum efficiency and consistency.

Browse Workflows
📖

Master Custom Rules

Discover advanced techniques for creating custom rules and mastering Antigravity.

Complete Guide