Skip to content

ginuerzh/gost vulnerable to Timing Attack

Moderate severity GitHub Reviewed Published May 21, 2023 in ginuerzh/gost • Updated Nov 4, 2023

Package

gomod github.com/ginuerzh/gost (Go)

Affected versions

<= 2.11.5

Patched versions

None

Description

Timing attacks occur when an attacker can guess a secret by observing a difference in processing time for valid and invalid inputs. Sensitive secrets such as passwords, token and API keys should be compared only using a constant-time comparision function.
More information on this attack type can be found in this blog post.

Root Cause Analysis

In this case, the vulnerability occurs due to the following code.

https://github.com/ginuerzh/gost/blob/1c62376e0880e4094bd3731e06bd4f7842638f6a/auth.go#L46-L46

Here, a untrusted input, sourced from a HTTP header, is compared directly with a secret.
Since, this comparision is not secure, an attacker can mount a side-channel timing attack to guess the password.

Remediation

This can be easily fixed using a constant time comparing function such as crypto/subtle's ConstantTimeCompare.
An example fix can be found in runatlantis/atlantis@4887091 Alternatively, one can apply the patch below

From d18cff85e1a565f688f717fd8f2cacea62ff9dbf Mon Sep 17 00:00:00 2001
From: Porcupiney Hairs <[email protected]>
Date: Sun, 7 May 2023 01:03:33 +0530
Subject: [PATCH] Fix : Timing attack

---
 auth.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/auth.go b/auth.go
index 1be96e9..be13f23 100644
--- a/auth.go
+++ b/auth.go
@@ -2,6 +2,7 @@ package gost
 
 import (
 	"bufio"
+	"crypto/subtle"
 	"io"
 	"strings"
 	"sync"
@@ -43,7 +44,8 @@ func (au *LocalAuthenticator) Authenticate(user, password string) bool {
 	}
 
 	v, ok := au.kvs[user]
-	return ok && (v == "" || password == v)
+	passOk := subtle.ConstantTimeCompare([]byte(password), []byte(v)) == 0
+	return ok && (v == "" || passOk)
 }
 
 // Add adds a key-value pair to the Authenticator.
-- 
2.25.1

References

@ginuerzh ginuerzh published to ginuerzh/gost May 21, 2023
Published to the GitHub Advisory Database May 22, 2023
Reviewed May 22, 2023
Published by the National Vulnerability Database May 30, 2023
Last updated Nov 4, 2023

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
Low
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N

EPSS score

0.145%
(51st percentile)

Weaknesses

CVE ID

CVE-2023-32691

GHSA ID

GHSA-qjrq-hm79-49ww

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.