CVE-2023-29008: @sveltejs/kit SvelteKit Framework Has Insufficient CSRF Vulnerability

HIGH
Advisory Identifier: GHSA-gv7g-x59x-wf8f
CVSS 8.8
CWE-918 CWE-352
Published
Advisory Summary

CVE-2023-29008 is a HIGH (CVSS 8.8) sveltekit framework has insufficient csrf vulnerability (CWE-918: Server-Side Request Forgery (SSRF)) affecting @sveltejs/kit libraries in the npm ecosystem. The issue involves sveltekit framework has insufficient csrf protection for cors requests. Remediation is available by upgrading affected packages to version 1.15.2.

CVE-2023-29008 at a Glance

CVE Identifier CVE-2023-29008
GHSA Identifier GHSA-gv7g-x59x-wf8f
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-918: Server-Side Request Forgery (SSRF)
Affected Product @sveltejs/kit
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2023-29008

To remediate this vulnerability, upgrade all affected @sveltejs/kit dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@sveltejs/kit fixed: 1.15.2
npm install @sveltejs/kit@1.15.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @sveltejs/kit

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2023-29008, inspect your project dependencies using npm:

npm ls @sveltejs/kit

Analyze the terminal output to locate any version of @sveltejs/kit in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.15.2), your application is affected.

Note: The npm ls @sveltejs/kit command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-918: Server-Side Request Forgery (SSRF), where the web server receives a url or similar request from an upstream component and retrieves the contents of this url, but it does not sufficiently ensure that the request is being sent to the expected destination. In @sveltejs/kit, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The SvelteKit framework offers developers an option to create simple REST APIs. This is done by defining a `+server.js` file, containing endpoint handlers for different HTTP methods. SvelteKit provides out-of-the-box cross-site request forgery (CSRF) protection to its users. The protection is implemented at `kit/src/runtime/server/respond.js`. While the implementation does a sufficient job of mitigating common CSRF attacks, the protection can be bypassed by simply specifying an upper-cased `Content-Type` header value. The browser will not send uppercase characters on form submission, but this check does not block all expected cross-site requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests ### Details The CSRF protection is implemented using the code shown below. ``` javascript const forbidden = is_form_content_type(request) && (request.method === 'POST' || request.method === 'PUT' || request.method === 'PATCH' || request.method === 'DELETE') && request.headers.get('origin') !== url.origin; if (forbidden) { const csrf_error = error(403, `Cross-site ${request.method} form submissions are forbidden`); if (request.headers.get('accept') === 'application/json') { return json(csrf_error.body, { status: csrf_error.status }); } return text(csrf_error.body.message, { status: csrf_error.status }); } ``` If the incoming request specifies a POST/PUT/PATCH/DELETE method, the protection will compare the server’s origin with the value of the HTTP Origin header. A mismatch between these values signals that a potential attack has been detected. The final check is performed on the request’s `Content-Type` header whether the value is either `application/x-www-form-urlencoded`, `multipart/form-data` or `text/plain`. If all the previous checks pass, the request will be rejected with an 403 error response. However, `is_form_content_type`, which is responsible for checking the value of the `Content-Type` header, is not sufficient to mitigate all possible variations of this type of attack. Since this function is checking `Content-Type` with lower-cased values, and the browser accepts upper-cased `Content-Type` header to be sent, a CSRF attack performed with the `Content-Type` header that contains an upper-cased character (e.g., `text/plaiN`) can circumvent the protection and the request will be processed by the endpoint handler. <!-- ### PoC 1. Set up the SvelteKit with `POST /api/test` endpoint. 2. Replace `REPLACE_DOMAIN` in the following HTML. ``` html <script> (async() => { await fetch("https://REPLACE_DOMAIN/api/test", {method: "POST", headers:{"Content-Type":"text/plaiN"}, body: "hello=world"}); })(); </script> ``` 3. Confirm that a POST request is processed by the server. --> ### Impact If abused, this issue will allow malicious requests to be submitted from third-party domains, which can allow execution of operations within the context of the victim's session, and in extreme scenarios can lead to unauthorized access to users’ accounts. This may lead to all POST operations requiring authentication being allowed in the following cases: 1. If the target site sets `SameSite=None` on its auth cookie and the user visits a malicious site in a Chromium-based browser 2. If the target site doesn't set the `SameSite` attribute explicitly and the user visits a malicious site with Firefox/Safari with tracking protections turned off. 3. If the user is visiting a malicious site with a very outdated browser. ### Remediations It is preferred to update to SvelteKit 1.15.2. It is also recommended to explicitly set `SameSite` to a value other than `None` on authentication cookies especially if the upgrade cannot be done in a timely manner.

CVE-2023-29008 Affected @sveltejs/kit Versions

1 component(s)
Fixed Versions:
1.15.2
Product / Package Ecosystem Affected Versions Fixed Version
@sveltejs/kit
npm
< 1.15.2
1.15.2

References

Frequently Asked Questions

What is CVE-2023-29008?
CVE-2023-29008 is a security vulnerability in @sveltejs/kit involving SvelteKit framework has Insufficient CSRF protection for CORS requests under CWE-918: Server-Side Request Forgery (SSRF).
Which @sveltejs/kit versions are affected?
Affected versions include releases prior to 1.15.2 across affected packages: @sveltejs/kit.
What version fixes CVE-2023-29008?
Upgrading to 1.15.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @sveltejs/kit affected?
Yes, @sveltejs/kit is affected in releases prior to 1.15.2. Upgrade your dependency to 1.15.2 or later.
What is the CVSS score of CVE-2023-29008?
CVE-2023-29008 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2023-29008?
CVE-2023-29008 is classified under CWE-918: Server-Side Request Forgery (SSRF) (The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.).
How can I check npm dependencies for CVE-2023-29008?
Run the dependency tree command: 'npm ls @sveltejs/kit'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-gv7g-x59x-wf8f",
  "modified" : "2023-04-14T20:30:47Z",
  "published" : "2023-04-07T19:23:31Z",
  "aliases" : [ "CVE-2023-29008" ],
  "summary" : "SvelteKit framework has Insufficient CSRF protection for CORS requests",
  "details" : "### Summary\nThe SvelteKit framework offers developers an option to create simple REST APIs. This is done by defining a `+server.js` file, containing endpoint handlers for different HTTP methods.\n\nSvelteKit provides out-of-the-box cross-site request forgery (CSRF) protection to its users. The protection is implemented at `kit/src/runtime/server/respond.js`. While the implementation does a sufficient job of mitigating common CSRF attacks, the protection can be bypassed by simply specifying an upper-cased `Content-Type` header value. The browser will not send uppercase characters on form submission, but this check does not block all expected cross-site requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests\n\n### Details\nThe CSRF protection is implemented using the code shown below.\n\n``` javascript\n\t\tconst forbidden =\n\t\t\tis_form_content_type(request) &&\n\t\t\t(request.method === 'POST' ||\n\t\t\t\trequest.method === 'PUT' ||\n\t\t\t\trequest.method === 'PATCH' ||\n\t\t\t\trequest.method === 'DELETE') &&\n\t\t\trequest.headers.get('origin') !== url.origin;\n\n\t\tif (forbidden) {\n\t\t\tconst csrf_error = error(403, `Cross-site ${request.method} form submissions are forbidden`);\n\t\t\tif (request.headers.get('accept') === 'application/json') {\n\t\t\t\treturn json(csrf_error.body, { status: csrf_error.status });\n\t\t\t}\n\t\t\treturn text(csrf_error.body.message, { status: csrf_error.status });\n\t\t}\n```\n\nIf the incoming request specifies a POST/PUT/PATCH/DELETE method, the protection will compare the server’s origin with the value of the HTTP Origin header. A mismatch between these values signals that a potential attack has been detected. The final check is performed on the request’s `Content-Type` header whether the value is either `application/x-www-form-urlencoded`, `multipart/form-data` or `text/plain`. If all the previous checks pass, the request will be rejected with an 403 error response.\nHowever, `is_form_content_type`, which is responsible for checking the value of the `Content-Type` header, is not sufficient to mitigate all possible variations of this type of attack. Since this function is checking `Content-Type` with lower-cased values, and the browser accepts upper-cased `Content-Type` header to be sent, a CSRF attack performed with the `Content-Type` header that contains an upper-cased character (e.g., `text/plaiN`) can circumvent the protection and the request will be processed by the endpoint handler.\n<!--\n### PoC\n1. Set up the SvelteKit with `POST /api/test` endpoint.\n2. Replace `REPLACE_DOMAIN` in the following HTML.\n``` html\n<script>\n(async() => {\n\tawait fetch(\"https://REPLACE_DOMAIN/api/test\", {method: \"POST\", headers:{\"Content-Type\":\"text/plaiN\"}, body: \"hello=world\"});\n})();\n</script>\n```\n3. Confirm that a POST request is processed by the server.\n-->\n### Impact\nIf abused, this issue will allow malicious requests to be submitted from third-party domains, which can allow execution of operations within the context of the victim's session, and in extreme scenarios can lead to unauthorized access to users’ accounts. This may lead to all POST operations requiring authentication being allowed in the following cases:\n1. If the target site sets `SameSite=None` on its auth cookie and the user visits a malicious site in a Chromium-based browser\n2. If the target site doesn't set the `SameSite` attribute explicitly and the user visits a malicious site with Firefox/Safari with tracking protections turned off.\n3. If the user is visiting a malicious site with a very outdated browser.\n\n### Remediations\nIt is preferred to update to SvelteKit 1.15.2. It is also recommended to explicitly set `SameSite` to a value other than `None` on authentication cookies especially if the upgrade cannot be done in a timely manner.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@sveltejs/kit"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.15.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/sveltejs/kit/security/advisories/GHSA-gv7g-x59x-wf8f"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-29008"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sveltejs/kit/commit/ba436c6685e751d968a960fbda65f24cf7a82e9f"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sveltejs/kit"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-352", "CWE-918" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-04-07T19:23:31Z",
    "nvd_published_at" : "2023-04-06T17:15:00Z"
  }
}