CVE-2021-32637: Github.com/authelia/authelia/v4 Authentication Bypass Vulnerability

CRITICAL
Advisory Identifier: GHSA-68wm-pfjf-wqp6
CVSS 10.0
CWE-287
Published
Advisory Summary

CVE-2021-32637 is a CRITICAL (CVSS 10.0) authentication bypass vulnerability (CWE-287: Improper Authentication) affecting Github.com/authelia/authelia/v4 libraries in the Go ecosystem. The issue involves authelia vulnerable to an authentication bypassed with malformed request uri on nginx. Remediation is available by upgrading affected packages to version 4.29.3.

CVE-2021-32637 at a Glance

CVE Identifier CVE-2021-32637
GHSA Identifier GHSA-68wm-pfjf-wqp6
Severity CRITICAL
CVSS v3.1 Base Score 10.0
CWE Classification CWE-287: Improper Authentication
Affected Product Github.com/authelia/authelia/v4
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 10.0

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:N/S:C/C:H/I:H/A:H).

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

How to Fix CVE-2021-32637

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

github.com/authelia/authelia/v4 fixed: 4.29.3
Upgrade github.com/authelia/authelia/v4 to 4.29.3
Verify Direct and Transitive Dependencies

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

inspect dependencies for github.com/authelia/authelia/v4

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-32637, inspect your project dependencies for Github.com/authelia/authelia/v4:

inspect dependencies for github.com/authelia/authelia/v4

Analyze the terminal output to locate any version of Github.com/authelia/authelia/v4 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.29.3), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-287: Improper Authentication, where when an actor claims to have a given identity, the product does not prove or insufficiently proves that the claim is correct. In Github.com/authelia/authelia/v4, 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

### Impact This affects uses who are using nginx ngx_http_auth_request_module with Authelia, it allows a malicious individual who crafts a malformed HTTP request to bypass the authentication mechanism. It additionally could theoretically affect other proxy servers, but all of the ones we officially support except nginx do not allow malformed URI paths. ### Patches The problem is rectified entirely in v4.29.3. As this patch is relatively straightforward we can back port this to any version upon request. Alternatively we are supplying a git patch to 4.25.1 which should be relatively straightforward to apply to any version, the git patches for specific versions can be found below. <details><summary>Patch for 4.25.1:</summary><p> ```patch From ca22f3d2c44ca7bef043ffbeeb06d6659c1d550f Mon Sep 17 00:00:00 2001 From: James Elliott <james-d-elliott@users.noreply.github.com> Date: Wed, 19 May 2021 12:10:13 +1000 Subject: [PATCH] fix(handlers): verify returns 200 on malformed request This is a git patch for commit at tag v4.25.1 to address a potential method to bypass authentication in proxies that forward malformed information to Authelia in the forward auth process. Instead of returning a 200 this ensures that Authelia returns a 401 when this occurs. --- internal/handlers/handler_verify.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/handlers/handler_verify.go b/internal/handlers/handler_verify.go index 65c064ce..4dd9702d 100644 --- a/internal/handlers/handler_verify.go +++ b/internal/handlers/handler_verify.go @@ -396,7 +396,9 @@ func VerifyGet(cfg schema.AuthenticationBackendConfiguration) middlewares.Reques targetURL, err := getOriginalURL(ctx) if err != nil { - ctx.Error(fmt.Errorf("Unable to parse target URL: %s", err), operationFailedMessage) + ctx.Logger.Error(fmt.Errorf("Unable to parse target URL: %s", err)) + ctx.ReplyUnauthorized() + return } -- 2.31.1 ``` </p></details> ### Workarounds The most relevant workaround is upgrading. **If you need assistance with an upgrade please contact us on [Matrix](https://riot.im/app/#/room/#authelia:matrix.org) or [Discord](https://discord.authelia.com).** Please just let us know you're needing help upgrading to above 4.29.2. You can add an block which fails requests that contains a malformed URI in the internal location block. We have crafted one that should work in most instances, it basically checks no chars that are required to be URL-encoded for either the path or the query are in the URI. Basically this regex checks that the characters between the square braces are the only characters in the $request_uri header, if they exist, it returns a HTTP 401 status code. The characters in the regex match are tested to not cause a parsing error that would result in a failure, however they are not exhaustive since query strings seem to not always conform to the RFC. <details><summary>authelia.conf:</summary><p> ```nginx location /authelia { internal; # **IMPORTANT** # This block rejects requests with a 401 which contain characters that are unable to be parsed. # It is necessary for security prior to v4.29.3 due to the fact we returned an invalid code in the event of a parser error. # You may comment this section if you're using Authelia v4.29.3 or above. We strongly recommend upgrading. # RFC3986: http://tools.ietf.org/html/rfc3986 # Commentary on RFC regarding Query Strings: https://www.456bereastreet.com/archive/201008/what_characters_are_allowed_unencoded_in_query_strings/ if ($request_uri ~ [^a-zA-Z0-9_+-=\!@$%&*?~.:#'\;\(\)\[\]]) { return 401; } # Include the remainder of the block here. } ```` </p></details> ### Discovery This issue was discovered by: Siemens Energy Cybersecurity Red Team - Silas Francisco - Ricardo Pesqueira ### Identifying active exploitation of the vulnerability The following regex should match log entries that are an indication of the vulnerability being exploited: ```regex level=error msg="Unable to parse target URL: Unable to parse URL (extracted from X-Original-URL header)?.*?: parse.*?net/url:.*github\.com/authelia/authelia/internal/handlers/handler_verify\.go ``` Example log entry ***with*** X-Original-URL configured: ```log time="2021-05-21T16:31:15+10:00" level=error msg="Unable to parse target URL: Unable to parse URL extracted from X-Original-URL header: parse \"https://example.com/": net/url: invalid control character in URL" method=GET path=/api/verify remote_ip=192.168.1.10 stack="github.com/authelia/authelia/internal/middlewares/authelia_context.go:65 (*AutheliaCtx).Error\ngithub.com/authelia/authelia/internal/handlers/handler_verify.go:431 VerifyGet.func1\ngithub.com/authelia/authelia/internal/middlewares/authelia_context.go:50 AutheliaMiddleware.func1.1\ngithub.com/fasthttp/router@v1.3.12/router.go:414 (*Router).Handler\ngithub.com/authelia/authelia/internal/middlewares/log_request.go:14 LogRequestMiddleware.func1\ngithub.com/valyala/fasthttp@v1.24.0/server.go:2219 (*Server).serveConn\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:223 (*workerPool).workerFunc\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:195 (*workerPool).getCh.func1\nruntime/asm_amd64.s:1371 goexit" ``` Example log entry ***without*** X-Original-URL configured: ```log time="2021-05-21T16:30:17+10:00" level=error msg="Unable to parse target URL: Unable to parse URL https://example.com/: parse \"https://example.com/": net/url: invalid control character in URL" method=GET path=/api/verify remote_ip=192.168.1.10 stack="github.com/authelia/authelia/internal/middlewares/authelia_context.go:65 (*AutheliaCtx).Error\ngithub.com/authelia/authelia/internal/handlers/handler_verify.go:431 VerifyGet.func1\ngithub.com/authelia/authelia/internal/middlewares/authelia_context.go:50 AutheliaMiddleware.func1.1\ngithub.com/fasthttp/router@v1.3.12/router.go:414 (*Router).Handler\ngithub.com/authelia/authelia/internal/middlewares/log_request.go:14 LogRequestMiddleware.func1\ngithub.com/valyala/fasthttp@v1.24.0/server.go:2219 (*Server).serveConn\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:223 (*workerPool).workerFunc\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:195 (*workerPool).getCh.func1\nruntime/asm_amd64.s:1371 goexit" ``` ### For more information If you have any questions or comments about this advisory: * Open a [Discussion](https://github.com/authelia/authelia/discussions) * Email us at [security@authelia.com](mailto:security@authelia.com) ### Edit / Adjustment This CVE has been edited adjusting the score to more accurately reflect the guidance in the [official CVSS 3.1 guide](https://www.first.org/cvss/specification-document). Due to misunderstandings about the CVSS indicators this was incorrectly assigned but this has been corrected. Under close evaluation the score we originally assigned to this CVE is inappropriate in two clearly identifiable criteria: - Complexity (Low -> High): This attack requires the administrator be using NGINX's auth_request module. This means the attack cannot be exploited at will but rather requires a pre-condition separate to the vulnerable system outside of the attackers control (a vulnerable version of NGINX - at the time of this writing NGINX's security team has *refused* to fix the clear bug on their end but that's effectively irrelevant since we operate with more than just a NGINX proxy and no other proxy has this vulnerability), and requires the attacker have gathered knowledge about the system for this likely to be exploited. - Availability (High -> None): This attack does not alter availability directly.

CVE-2021-32637 Affected Github.com/authelia/authelia/v4 Versions

1 component(s)
Fixed Versions:
4.29.3
Product / Package Ecosystem Affected Versions Fixed Version
github.com/authelia/authelia/v4
Go
≥ 4.0.0-alpha1
< 4.29.3
4.29.3

References

Frequently Asked Questions

What is CVE-2021-32637?
CVE-2021-32637 is a security vulnerability in Github.com/authelia/authelia/v4 involving Authelia vulnerable to an authentication bypassed with malformed request URI on nginx under CWE-287: Improper Authentication.
Which Github.com/authelia/authelia/v4 versions are affected?
Affected versions include releases prior to 4.29.3 across affected packages: github.com/authelia/authelia/v4.
What version fixes CVE-2021-32637?
Upgrading to 4.29.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/authelia/authelia/v4 affected?
Yes, github.com/authelia/authelia/v4 is affected in releases prior to 4.29.3. Upgrade your dependency to 4.29.3 or later.
What is the CVSS score of CVE-2021-32637?
CVE-2021-32637 has a CVSS v3.1 base score of 10.0 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2021-32637?
CVE-2021-32637 is classified under CWE-287: Improper Authentication (When an actor claims to have a given identity, the product does not prove or insufficiently proves that the claim is correct.).
How can I check Go dependencies for CVE-2021-32637?
Run the dependency tree command: 'inspect dependencies for github.com/authelia/authelia/v4'. 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-68wm-pfjf-wqp6",
  "modified" : "2024-04-22T14:49:49Z",
  "published" : "2021-12-20T16:57:16Z",
  "aliases" : [ "CVE-2021-32637" ],
  "summary" : "Authelia vulnerable to an authentication bypassed with malformed request URI on nginx",
  "details" : "### Impact\nThis affects uses who are using nginx ngx_http_auth_request_module with Authelia, it allows a malicious individual who crafts a malformed HTTP request to bypass the authentication mechanism. It additionally could theoretically affect other proxy servers, but all of the ones we officially support except nginx do not allow malformed URI paths.\n\n### Patches\nThe problem is rectified entirely in v4.29.3. As this patch is relatively straightforward we can back port this to any version upon request. Alternatively we are supplying a git patch to 4.25.1 which should be relatively straightforward to apply to any version, the git patches for specific versions can be found below.\n\n<details><summary>Patch for 4.25.1:</summary><p>\n\n```patch\nFrom ca22f3d2c44ca7bef043ffbeeb06d6659c1d550f Mon Sep 17 00:00:00 2001\nFrom: James Elliott <james-d-elliott@users.noreply.github.com>\nDate: Wed, 19 May 2021 12:10:13 +1000\nSubject: [PATCH] fix(handlers): verify returns 200 on malformed request\n\nThis is a git patch for commit at tag v4.25.1 to address a potential method to bypass authentication in proxies that forward malformed information to Authelia in the forward auth process. Instead of returning a 200 this ensures that Authelia returns a 401 when this occurs.\n---\n internal/handlers/handler_verify.go | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/internal/handlers/handler_verify.go b/internal/handlers/handler_verify.go\nindex 65c064ce..4dd9702d 100644\n--- a/internal/handlers/handler_verify.go\n+++ b/internal/handlers/handler_verify.go\n@@ -396,7 +396,9 @@ func VerifyGet(cfg schema.AuthenticationBackendConfiguration) middlewares.Reques\n \t\ttargetURL, err := getOriginalURL(ctx)\n \n \t\tif err != nil {\n-\t\t\tctx.Error(fmt.Errorf(\"Unable to parse target URL: %s\", err), operationFailedMessage)\n+\t\t\tctx.Logger.Error(fmt.Errorf(\"Unable to parse target URL: %s\", err))\n+\t\t\tctx.ReplyUnauthorized()\n+\n \t\t\treturn\n \t\t}\n \n-- \n2.31.1\n```\n\n</p></details>\n\n### Workarounds\nThe most relevant workaround is upgrading. **If you need assistance with an upgrade please contact us on [Matrix](https://riot.im/app/#/room/#authelia:matrix.org) or [Discord](https://discord.authelia.com).** Please just let us know you're needing help upgrading to above 4.29.2. \n\nYou can add an block which fails requests that contains a malformed URI in the internal location block. We have crafted one that should work in most instances, it basically checks no chars that are required to be URL-encoded for either the path or the query are in the URI. Basically this regex checks that the characters between the square braces are the only characters in the $request_uri header, if they exist, it returns a HTTP 401 status code. The characters in the regex match are tested to not cause a parsing error that would result in a failure, however they are not exhaustive since query strings seem to not always conform to the RFC.\n\n<details><summary>authelia.conf:</summary><p>\n\n```nginx\nlocation /authelia {\n    internal;\n    # **IMPORTANT**\n    # This block rejects requests with a 401 which contain characters that are unable to be parsed.\n    # It is necessary for security prior to v4.29.3 due to the fact we returned an invalid code in the event of a parser error.\n    # You may comment this section if you're using Authelia v4.29.3 or above. We strongly recommend upgrading.\n    # RFC3986: http://tools.ietf.org/html/rfc3986\n    # Commentary on RFC regarding Query Strings: https://www.456bereastreet.com/archive/201008/what_characters_are_allowed_unencoded_in_query_strings/\n    if ($request_uri ~ [^a-zA-Z0-9_+-=\\!@$%&*?~.:#'\\;\\(\\)\\[\\]]) {\n        return 401;\n    }\n\n    # Include the remainder of the block here. \n}\n````\n\n</p></details>\n\n### Discovery\n\nThis issue was discovered by:\n\nSiemens Energy\nCybersecurity Red Team\n\n- Silas Francisco\n- Ricardo Pesqueira\n\n\n### Identifying active exploitation of the vulnerability\n\nThe following regex should match log entries that are an indication of the vulnerability being exploited:\n```regex\nlevel=error msg=\"Unable to parse target URL: Unable to parse URL (extracted from X-Original-URL header)?.*?: parse.*?net/url:.*github\\.com/authelia/authelia/internal/handlers/handler_verify\\.go\n```\n\nExample log entry ***with*** X-Original-URL configured:\n```log\ntime=\"2021-05-21T16:31:15+10:00\" level=error msg=\"Unable to parse target URL: Unable to parse URL extracted from X-Original-URL header: parse \\\"https://example.com/\": net/url: invalid control character in URL\" method=GET path=/api/verify remote_ip=192.168.1.10 stack=\"github.com/authelia/authelia/internal/middlewares/authelia_context.go:65 (*AutheliaCtx).Error\\ngithub.com/authelia/authelia/internal/handlers/handler_verify.go:431     VerifyGet.func1\\ngithub.com/authelia/authelia/internal/middlewares/authelia_context.go:50 AutheliaMiddleware.func1.1\\ngithub.com/fasthttp/router@v1.3.12/router.go:414                         (*Router).Handler\\ngithub.com/authelia/authelia/internal/middlewares/log_request.go:14      LogRequestMiddleware.func1\\ngithub.com/valyala/fasthttp@v1.24.0/server.go:2219                       (*Server).serveConn\\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:223                    (*workerPool).workerFunc\\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:195                    (*workerPool).getCh.func1\\nruntime/asm_amd64.s:1371                                                 goexit\"\n```\n\nExample log entry ***without*** X-Original-URL configured:\n```log\ntime=\"2021-05-21T16:30:17+10:00\" level=error msg=\"Unable to parse target URL: Unable to parse URL https://example.com/: parse \\\"https://example.com/\": net/url: invalid control character in URL\" method=GET path=/api/verify remote_ip=192.168.1.10 stack=\"github.com/authelia/authelia/internal/middlewares/authelia_context.go:65 (*AutheliaCtx).Error\\ngithub.com/authelia/authelia/internal/handlers/handler_verify.go:431     VerifyGet.func1\\ngithub.com/authelia/authelia/internal/middlewares/authelia_context.go:50 AutheliaMiddleware.func1.1\\ngithub.com/fasthttp/router@v1.3.12/router.go:414                         (*Router).Handler\\ngithub.com/authelia/authelia/internal/middlewares/log_request.go:14      LogRequestMiddleware.func1\\ngithub.com/valyala/fasthttp@v1.24.0/server.go:2219                       (*Server).serveConn\\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:223                    (*workerPool).workerFunc\\ngithub.com/valyala/fasthttp@v1.24.0/workerpool.go:195                    (*workerPool).getCh.func1\\nruntime/asm_amd64.s:1371                                                 goexit\"\n```\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open a [Discussion](https://github.com/authelia/authelia/discussions)\n* Email us at [security@authelia.com](mailto:security@authelia.com)\n\n### Edit / Adjustment\n\nThis CVE has been edited adjusting the score to more accurately reflect the guidance in the [official CVSS 3.1 guide](https://www.first.org/cvss/specification-document). Due to misunderstandings about the CVSS indicators this was incorrectly assigned but this has been corrected. Under close evaluation the score we originally assigned to this CVE is inappropriate in two clearly identifiable criteria:\n\n- Complexity (Low -> High): This attack requires the administrator be using NGINX's auth_request module. This means the attack cannot be exploited at will but rather requires a pre-condition separate to the vulnerable system outside of the attackers control (a vulnerable version of NGINX - at the time of this writing NGINX's security team has *refused* to fix the clear bug on their end but that's effectively irrelevant since we operate with more than just a NGINX proxy and no other proxy has this vulnerability), and requires the attacker have gathered knowledge about the system for this likely to be exploited.\n - Availability (High -> None): This attack does not alter availability directly.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/authelia/authelia/v4"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0-alpha1"
      }, {
        "fixed" : "4.29.3"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 4.29.2"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/authelia/authelia/security/advisories/GHSA-68wm-pfjf-wqp6"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-32637"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/authelia/authelia/commit/c62dbd43d6e69ae81530e7c4f8763857f8ff1dda"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/authelia/authelia"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-287" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-05-28T18:08:47Z",
    "nvd_published_at" : "2021-05-28T17:15:00Z"
  }
}