Threat: Insecure Configuration Defaults
- Description: Attackers might exploit default, insecure configurations in Egg.js applications. For example, using the default cookie secret in production allows attackers to forge cookies and gain unauthorized access.
- Impact: Unauthorized access, data breaches, account takeover, compromise of application integrity.
- Egg Component Affected: Configuration system,
config/config.default.js
,config/config.prod.js
, Cookie signing. - Risk Severity: High
- Mitigation Strategies:
- Strong Configuration: Always override default configurations, especially in production.
- Secure Secrets Management: Use strong, randomly generated secrets for cookie signing and store them securely (e.g., environment variables, vault).
Threat: Exposure of Configuration Files
- Description: Attackers could access sensitive information by exploiting exposed configuration files. If files containing database credentials or API keys are publicly accessible, attackers can retrieve these secrets and compromise backend systems.
- Impact: Data breaches, unauthorized access to backend systems, compromise of external service accounts, information disclosure.
- Egg Component Affected: Configuration system,
config/config.default.js
,config/config.prod.js
, Static file serving. - Risk Severity: Critical
- Mitigation Strategies:
- Secure Deployment Practices: Ensure configuration files are not deployed to publicly accessible web directories.
- Restrict File Access: Configure web servers to prevent direct access to configuration files.
- Externalized Configuration: Utilize environment variables or secret management systems to store sensitive configuration values outside of files.
- Description: Attackers can exploit applications where security middleware (like
egg-security
) is misconfigured or disabled. Disabling CSRF protection or misconfiguring CSP weakens defenses against common web attacks like CSRF and XSS. - Impact: Cross-Site Scripting (XSS), Cross-Site Request Forgery (CSRF), clickjacking, other client-side attacks, data manipulation, unauthorized actions.
- Egg Component Affected:
egg-security
plugin, Middleware system, Request handling pipeline. - Risk Severity: High
- Mitigation Strategies:
- Enable and Configure Security Middleware: Ensure
egg-security
plugin is enabled and properly configured for CSRF, CSP, HSTS, etc. - Review Middleware Configuration: Carefully review the configuration of all security middleware components.
- Test Security Headers: Verify that security headers are correctly implemented and effective.
- Enable and Configure Security Middleware: Ensure
- Description: Attackers can exploit vulnerabilities in custom middleware developed for Egg.js applications. Flaws in custom authentication, authorization, or input validation middleware can lead to security bypasses or injection attacks.
- Impact: Authentication bypass, authorization bypass, injection attacks (SQL, command, header), data breaches, application compromise.
- Egg Component Affected: Middleware system, Custom middleware functions, Request handling pipeline.
- Risk Severity: High
- Mitigation Strategies:
- Secure Coding Practices: Follow secure coding principles when developing custom middleware, including input validation and secure authentication/authorization logic.
- Code Reviews: Conduct thorough code reviews of custom middleware.
- Security Testing: Perform security testing on custom middleware.
- Description: Attackers can exploit vulnerabilities in third-party Egg.js plugins (middleware). A vulnerable plugin can introduce security flaws into the application, potentially leading to various attacks depending on the vulnerability.
- Impact: Varies depending on the plugin vulnerability, but can include: XSS, SQL injection, authentication bypass, remote code execution, data breaches, application compromise.
- Egg Component Affected: Plugin system,
package.json
dependencies,node_modules
, Middleware system. - Risk Severity: High
- Mitigation Strategies:
- Dependency Management: Maintain an inventory of Egg.js plugins and their versions.
- Regular Updates: Keep Egg.js plugins and their dependencies up-to-date.
- Security Audits of Plugins: Evaluate the security posture of plugins before using them.
- Vulnerability Scanning: Use dependency vulnerability scanning tools to identify and address vulnerabilities in plugins.
- Description: Attackers can exploit vulnerabilities arising from incorrect usage of
ctx.service
and direct data access in controllers. If services lack authorization checks or controllers bypass services, attackers can gain unauthorized data access or perform unauthorized actions. - Impact: Unauthorized data access, data manipulation, data breaches, privilege escalation, business logic bypass.
- Egg Component Affected: Services (
ctx.service
), Controllers, Data access layer, Authorization logic. - Risk Severity: High
- Mitigation Strategies:
- Service Layer Enforcement: Always access data and perform business logic through well-defined services.
- Authorization in Services: Implement authorization checks within services.
- Input Validation in Services: Perform input validation within services.
Threat: Route Parameter Injection
- Description: Attackers can inject malicious payloads through route parameters if these parameters are not properly sanitized and validated. Unsanitized route parameters used in file paths can lead to path traversal, or in database queries to NoSQL injection.
- Impact: Path traversal, Local File Inclusion (LFI), Remote File Inclusion (RFI), NoSQL injection, command injection, data breaches, application compromise.
- Egg Component Affected: Routing system, Route parameters, Controllers, Data access layer, File system operations.
- Risk Severity: High
- Mitigation Strategies:
- Input Validation and Sanitization: Always validate and sanitize route parameters.
- Parameter Encoding: Properly encode route parameters.
- Principle of Least Privilege (File Access): Restrict file system access.
- Prepared Statements/Parameterized Queries (Database): Use prepared statements to prevent SQL/NoSQL injection.
- Description: Attackers can exploit known vulnerabilities in outdated versions of Egg.js core framework or its plugins. Publicly disclosed vulnerabilities can be easily exploited if applications are not updated.
- Impact: Varies depending on the vulnerability, but can range from XSS and CSRF to remote code execution and complete application compromise.
- Egg Component Affected: Egg.js core framework, Plugin system,
package.json
dependencies,node_modules
. - Risk Severity: Critical to High
- Mitigation Strategies:
- Regular Updates: Keep Egg.js core framework and all plugins updated to the latest stable versions.
- Vulnerability Monitoring: Subscribe to security advisories related to Node.js and Egg.js.
- Automated Dependency Updates: Use tools to automate dependency updates and vulnerability patching.
- Description: Attackers can exploit misconfigurations in session management in Egg.js cluster mode. Improper session storage sharing or synchronization can lead to session fixation, session hijacking, or inconsistent session states.
- Impact: Session fixation, session hijacking, unauthorized access, user impersonation, inconsistent application behavior.
- Egg Component Affected: Session management, Cluster mode, Session storage (e.g., Redis, database).
- Risk Severity: High
- Mitigation Strategies:
- Shared Session Storage: Use a shared session store (e.g., Redis, database) in cluster mode.
- Session Synchronization: Ensure proper session synchronization across worker processes.
- Secure Session Configuration: Configure session settings securely (HttpOnly, Secure, SameSite, timeout, key rotation).
- Description: Attackers can exploit vulnerabilities introduced by custom framework extensions built on top of Egg.js. Security flaws in these extensions can bypass standard Egg.js security features or introduce new attack vectors.
- Impact: Varies depending on the vulnerability in the custom extension, but can range from XSS and CSRF to remote code execution and application compromise.
- Egg Component Affected: Custom framework extensions, Middleware system, Plugin system, Custom code.
- Risk Severity: High
- Mitigation Strategies:
- Secure Development Practices for Extensions: Apply secure coding principles when developing custom framework extensions.
- Security Reviews of Extensions: Conduct thorough security reviews and code audits of custom extensions.
- Testing of Extensions: Perform security testing on custom extensions.