Skip to content

JS: Move cors-misconfiguration query from experimental to Security #20146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Jul 31, 2025

Moved cors-misconfiguration query outside experimental

Copy link
Contributor

github-actions bot commented Jul 31, 2025

QHelp previews:

javascript/ql/src/Security/CWE-942/CorsPermissiveConfiguration.qhelp

Permissive CORS configuration

A server can use CORS (Cross-Origin Resource Sharing) to relax the restrictions imposed by the Same-Origin Policy, allowing controlled, secure cross-origin requests when necessary.

A server with an overly permissive CORS configuration may inadvertently expose sensitive data or enable CSRF attacks, which allow attackers to trick users into performing unwanted operations on websites they're authenticated to.

Recommendation

When the origin is set to true, the server accepts requests from any origin, potentially exposing the system to CSRF attacks. Use false as the origin value or implement a whitelist of allowed origins instead.

When the origin is set to null, it can be exploited by an attacker who can deceive a user into making requests from a null origin, often hosted within a sandboxed iframe.

If the origin value is user-controlled, ensure that the data is properly sanitized and validated against a whitelist of allowed origins.

Example

In the following example, server_1 accepts requests from any origin because the value of origin is set to true. server_2 uses user-controlled data for the origin without validation.

import { ApolloServer } from 'apollo-server';
var https = require('https'),
    url = require('url');

var server = https.createServer(function () { });

server.on('request', function (req, res) {
    // BAD: origin is too permissive
    const server_1 = new ApolloServer({
        cors: { origin: true }
    });

    let user_origin = url.parse(req.url, true).query.origin;
    // BAD: CORS is controlled by user
    const server_2 = new ApolloServer({
        cors: { origin: user_origin }
    });
});

To fix these issues, server_1 uses a restrictive CORS configuration that is not vulnerable to CSRF attacks. server_2 properly validates user-controlled data against a whitelist before using it.

import { ApolloServer } from 'apollo-server';
var https = require('https'),
    url = require('url');

var server = https.createServer(function () { });

server.on('request', function (req, res) {
    // GOOD: origin is restrictive
    const server_1 = new ApolloServer({
        cors: { origin: false }
    });

    let user_origin = url.parse(req.url, true).query.origin;
    // GOOD: user data is properly sanitized
    const server_2 = new ApolloServer({
        cors: { origin: (user_origin === "https://allowed1.com" || user_origin === "https://allowed2.com") ? user_origin : false }
    });
});

References

@Napalys Napalys marked this pull request as ready for review July 31, 2025 11:15
@Napalys Napalys requested a review from a team as a code owner July 31, 2025 11:15
@Copilot Copilot AI review requested due to automatic review settings July 31, 2025 11:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR moves the CORS misconfiguration query from experimental to the main Security suite, making it part of the default security analysis.

  • Relocates the CORS permissive configuration query and supporting files from experimental/Security/CWE-942/ to Security/CWE-942/
  • Updates library imports to use the standard location and removes deprecated functionality
  • Adds Apollo Server modeling through external model files instead of custom QL code

Reviewed Changes

Copilot reviewed 16 out of 20 changed files in this pull request and generated no comments.

Show a summary per file
File Description
javascript/ql/src/Security/CWE-942/CorsPermissiveConfiguration.ql Updates query imports and improves naming from "overly CORS configuration" to "Permissive CORS configuration"
javascript/ql/src/Security/CWE-942/CorsPermissiveConfiguration.qhelp Adds comprehensive help documentation with improved formatting and clearer explanations
javascript/ql/lib/semmle/javascript/security/CorsPermissiveConfigurationQuery.qll Removes deprecated Configuration class and flow label classes
javascript/ql/lib/semmle/javascript/security/CorsPermissiveConfigurationCustomizations.qll Updates imports to use standard Cors framework and replaces custom Apollo modeling with model-based approach
javascript/ql/lib/ext/apollo-server.model.yml Adds Apollo Server type models and sink models to replace custom QL implementations
javascript/ql/test/query-tests/Security/CWE-942/CorsPermissiveConfiguration.qlref Creates new test reference pointing to the moved query location
Multiple test expectation files Updates expected query suite contents to include the new security query
Comments suppressed due to low confidence (1)

javascript/ql/src/Security/CWE-942/CorsPermissiveConfiguration.ql:2

  • The query name should be 'CORS misconfiguration' to match the title mentioned in the change notes and maintain consistency with existing naming conventions.
 * @name Permissive CORS configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy