HIGH CWE-757 Authentication & Authorization

CWE-757 in APIs

CWE ID
CWE-757
Category
Encryption
Severity
HIGH
Short Name
Algorithm Downgrade

What is CWE-757?

CWE-757, titled Selection of Less-Secure Algorithm During Failover, describes a weakness where a system falls back to a less secure cryptographic algorithm when a preferred algorithm fails. This creates a scenario where security can be bypassed simply by triggering the failure condition.

The weakness occurs when developers implement failover mechanisms that automatically degrade security rather than failing securely. For example, if an API endpoint attempts to use TLS 1.3 for encryption but falls back to TLS 1.0 when 1.3 isn't available, an attacker can force the less secure connection by blocking or interfering with the preferred protocol.

This represents a fundamental violation of the principle of secure defaults and creates an attack surface that's significantly easier to exploit than the primary security mechanism.

CWE-757 in API Contexts

In API security, CWE-757 manifests in several critical ways that directly impact the confidentiality and integrity of data in transit.

Protocol Version Fallback: Many APIs implement TLS version negotiation but include fallback to older, vulnerable versions. An API might attempt TLS 1.3 but automatically fall back to TLS 1.0 or even SSL 3.0 if the preferred version fails. This creates a downgrade attack vector where an attacker can force the use of broken encryption.

Cipher Suite Selection: APIs often negotiate cipher suites, selecting the strongest available. However, if the negotiation fails, some implementations fall back to weaker ciphers like DES, 3DES, or even RC4. These algorithms are known to be vulnerable to various attacks including brute force and cryptanalysis.

Authentication Fallback: Some APIs implement multi-factor authentication but fall back to single-factor when the primary method fails. For instance, if biometric authentication fails, the system might automatically allow password-only authentication without proper rate limiting or additional verification.

API Gateway Configurations: API gateways sometimes implement protocol translation that inadvertently introduces downgrade vulnerabilities. A gateway might accept modern JWT tokens but fall back to basic authentication if token validation fails, creating a privilege escalation path.

The common thread is that these fallbacks create a 'back door' that bypasses the intended security controls, often with minimal effort required from an attacker.

Detection

Detecting CWE-757 requires both static analysis of configuration files and dynamic testing of actual API endpoints.

Configuration Analysis: Review TLS/SSL configurations, cipher suite lists, and authentication settings. Look for explicit fallback configurations that specify weaker algorithms. Check for wildcard or catch-all fallback settings that might activate when specific algorithms fail.

Protocol Testing: Use tools like openssl s_client to test API endpoints with various protocol versions. Attempt connections using older TLS versions and observe if the server accepts them. For example:

openssl s_client -connect api.example.com:443 -tls1

Cipher Suite Testing: Test with specific cipher suites known to be weak. Attempt connections using deprecated algorithms and verify whether the server negotiates them.

Authentication Bypass Testing: Test API endpoints with various authentication methods. If multi-factor authentication is implemented, attempt to bypass it by triggering failures in the primary factor.

Automated Scanning with middleBrick: middleBrick's security scanning engine includes specific checks for CWE-757 vulnerabilities. The scanner tests API endpoints for protocol downgrade vulnerabilities, weak cipher suite acceptance, and authentication fallback mechanisms. middleBrick runs 12 parallel security checks including protocol security analysis that specifically looks for these downgrade scenarios.

The middleBrick CLI makes this testing straightforward:

npx middlebrick scan https://api.example.com/v1/users

This command analyzes the API endpoint and reports any detected downgrade vulnerabilities, providing severity levels and specific remediation guidance for each finding.

Remediation

Fixing CWE-757 vulnerabilities requires eliminating fallback mechanisms and implementing secure defaults that fail closed rather than open.

Protocol Configuration: Configure servers to only accept the minimum required TLS version. For most modern APIs, this means TLS 1.2 or higher. Remove all fallback configurations:

# NGINX configuration - reject weak protocols
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers HIGH:!aNULL:!MD5:!RC4;

Cipher Suite Hardening: Explicitly specify only strong cipher suites and reject all others. Never include weak or deprecated algorithms:

# Apache configuration
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder on

Authentication Design: Implement authentication that fails securely. If primary authentication fails, the system should reject the request rather than falling back to weaker methods:

function authenticateRequest(request) {
    const primaryAuth = verifyMFA(request);
    if (!primaryAuth) {
        // Fail closed - do not fall back to weaker auth
        return { success: false, reason: 'Authentication failed' };
    }
    return { success: true };
}

API Gateway Security: Configure API gateways to enforce consistent security policies across all endpoints. Disable any protocol translation that might introduce downgrade vulnerabilities:

// Express.js middleware for strict security
app.use((req, res, next) => {
    if (req.secure || req.protocol === 'https') {
        next();
    } else {
        // Reject HTTP - no fallback to insecure
        res.status(403).json({ error: 'HTTPS required' });
    }
});

Testing and Validation: After implementing fixes, retest using the same methods as detection. Verify that no fallback mechanisms exist and that the system properly rejects attempts to use weaker security.

Continuous Monitoring: Implement monitoring to detect any configuration changes that might reintroduce downgrade vulnerabilities. middleBrick's Pro plan includes continuous scanning that can alert you if security configurations drift over time.

The key principle is to design systems that either work with the intended security level or fail completely, never degrading to less secure states.

Frequently Asked Questions

How does CWE-757 differ from CWE-327 (Use of Broken Algorithm)?
CWE-327 involves using a broken algorithm by choice, while CWE-757 involves intentionally falling back to weaker algorithms when preferred ones fail. CWE-757 is about the failover mechanism itself being insecure, whereas CWE-327 is about poor algorithm selection regardless of failure conditions.
Can CWE-757 vulnerabilities be detected in compiled API binaries?
Yes, but it requires dynamic testing rather than static analysis. You need to test the actual API endpoints with various protocol versions and authentication methods to observe fallback behavior. Tools like middleBrick can automate this testing by scanning live API endpoints and identifying downgrade vulnerabilities.