Fix timing attack on signin
Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
@@ -505,7 +505,7 @@ func (s AuthService) CheckCredentials(
|
|||||||
// Perform a password comparison even when the identity does not exist to mitigate timing attacks
|
// Perform a password comparison even when the identity does not exist to mitigate timing attacks
|
||||||
// and prevent revealing account existence.
|
// and prevent revealing account existence.
|
||||||
if identity.ID == gid.Nil {
|
if identity.ID == gid.Nil {
|
||||||
_, _ = s.hp.ComparePasswordAndHash([]byte(password+"qwertyuiop1234567890"), []byte("qwertyuiop1234567890"))
|
_, _ = s.hp.ComparePasswordAndHash([]byte(password), s.dummyHash)
|
||||||
return NewInvalidCredentialsError("invalid email or password")
|
return NewInvalidCredentialsError("invalid email or password")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ type (
|
|||||||
pg *pg.Client
|
pg *pg.Client
|
||||||
fm *filemanager.Service
|
fm *filemanager.Service
|
||||||
hp *passwdhash.Profile
|
hp *passwdhash.Profile
|
||||||
|
dummyHash []byte
|
||||||
baseURL string
|
baseURL string
|
||||||
tokenSecret string
|
tokenSecret string
|
||||||
disableSignup bool
|
disableSignup bool
|
||||||
@@ -99,6 +100,15 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func mustHashDummy(hp *passwdhash.Profile) []byte {
|
||||||
|
h, err := hp.HashPassword([]byte("dummy"))
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("cannot hash dummy password: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
func NewService(
|
func NewService(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
pgClient *pg.Client,
|
pgClient *pg.Client,
|
||||||
@@ -126,6 +136,7 @@ func NewService(
|
|||||||
pg: pgClient,
|
pg: pgClient,
|
||||||
fm: fm,
|
fm: fm,
|
||||||
hp: hp,
|
hp: hp,
|
||||||
|
dummyHash: mustHashDummy(hp),
|
||||||
baseURL: cfg.BaseURL.String(),
|
baseURL: cfg.BaseURL.String(),
|
||||||
tokenSecret: cfg.TokenSecret,
|
tokenSecret: cfg.TokenSecret,
|
||||||
disableSignup: cfg.DisableSignup,
|
disableSignup: cfg.DisableSignup,
|
||||||
|
|||||||
Reference in New Issue
Block a user