GHSA-R75M-26CQ-MJXC
Vulnerability from github – Published: 2024-03-28 17:53 – Updated: 2024-03-28 17:53Description
Improved security for stored password hashes
Serverpod now uses the OWASP, source, recommended Argon2Id password hash algorithm to store password hashes for the email authentication module.
Starting from Serverpod 1.2.6 all users that either creates an account or authenticates with the server will have their password stored using the safer algorithm. No changes are required from the developer to start storing passwords using the safer algorithm.
Why did we change how passwords are stored?
An issue was identified with the old password hash algorithm that made it susceptible to rainbow attacks if the database was compromised.
It is strongly recommended to migrate your existing password hashes.
Migrate existing password hashes
The email authentication module provides a helper method to migrate all the existing legacy password hashes in the database. Simply call Emails.migrateLegacyPasswordHashes(...) with a session instance as an argument to migrate the password hashes.
The method is implemented as an idempotent operation and will yield the same result regardless of how many times it is called.
We recommend either implementing a web server route that can be called remotely or by calling the method as part of starting the server.
Following is example code for implementing a web server route.
Web server route code
import 'dart:io';
import 'package:serverpod/serverpod.dart';
import 'package:serverpod_auth_server/module.dart' as auth;
class MigratePasswordsRoute extends Route {
@override
Future<bool> handleCall(Session session, HttpRequest request) async {
request.response.writeln(
'Migrating legacy passwords, check the server logs for progress updates.',
);
_migratePasswords(session);
return true;
}
}
Future<void> _migratePasswords(Session session) async {
session.log('Starting to migrate passwords.');
var totalMigratedPasswords = 0;
while (true) {
try {
var entriesMigrated = await auth.Emails.migrateLegacyPasswordHashes(
session,
// Process 100 database entries at a time
batchSize: 100,
// Stop after 500 entries have been migrated
maxMigratedEntries: 500,
);
totalMigratedPasswords += entriesMigrated;
session.log(
'Migrated $entriesMigrated password entries, total $totalMigratedPasswords.',
);
if (entriesMigrated == 0) break;
// Delay to avoid overloading the database
await Future.delayed(Duration(seconds: 1));
} catch (e) {
session.log('Error migrating passwords: $e');
}
}
session.log('Finished migrating passwords.');
}
How we migrate existing password hashes
Since password hashes can’t be recalculated without knowledge of the plain text password, the method in the email authentication module applies the new algorithm to the already stored password hashes.
When the affected users later authenticate, their password hash will be calculated using both algorithms in tandem. If the authentication is accepted, the stored password hash will be updated to only use the new algorithm so that further authentication only needs to run the new algorithm.
Impact
All versions of serverpod_auth_server pre 1.2.6
Patches
Upgrading to version 1.2.6 resolves this issue.
{
"affected": [
{
"package": {
"ecosystem": "Pub",
"name": "serverpod_auth_server"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "1.2.6"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2024-29886"
],
"database_specific": {
"cwe_ids": [
"CWE-916"
],
"github_reviewed": true,
"github_reviewed_at": "2024-03-28T17:53:42Z",
"nvd_published_at": "2024-03-27T19:15:49Z",
"severity": "MODERATE"
},
"details": "## Description\n\n### Improved security for stored password hashes\nServerpod now uses the OWASP, [source](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#introduction), recommended Argon2Id password hash algorithm to store password hashes for the email authentication module.\n\nStarting from Serverpod `1.2.6` all users that either creates an account or authenticates with the server will have their password stored using the safer algorithm. No changes are required from the developer to start storing passwords using the safer algorithm.\n\n### Why did we change how passwords are stored?\nAn issue was identified with the old password hash algorithm that made it susceptible to rainbow attacks if the database was compromised.\n\nIt is strongly recommended to migrate your existing password hashes.\n\n### Migrate existing password hashes\nThe email authentication module provides a helper method to migrate all the existing legacy password hashes in the database. Simply call `Emails.migrateLegacyPasswordHashes(...)` with a session instance as an argument to migrate the password hashes.\n\nThe method is implemented as an idempotent operation and will yield the same result regardless of how many times it is called.\n\nWe recommend either implementing a web server route that can be called remotely or by calling the method as part of starting the server.\n\nFollowing is example code for implementing a web server route.\n\n\u003cdetails\u003e\u003csummary\u003e\u003ch4\u003eWeb server route code\u003c/h4\u003e\u003c/summary\u003e\n\n```dart\nimport \u0027dart:io\u0027;\n\nimport \u0027package:serverpod/serverpod.dart\u0027;\nimport \u0027package:serverpod_auth_server/module.dart\u0027 as auth;\n\nclass MigratePasswordsRoute extends Route {\n @override\n Future\u003cbool\u003e handleCall(Session session, HttpRequest request) async {\n request.response.writeln(\n \u0027Migrating legacy passwords, check the server logs for progress updates.\u0027,\n );\n _migratePasswords(session);\n return true;\n }\n}\n\nFuture\u003cvoid\u003e _migratePasswords(Session session) async {\n session.log(\u0027Starting to migrate passwords.\u0027);\n\n var totalMigratedPasswords = 0;\n while (true) {\n try {\n var entriesMigrated = await auth.Emails.migrateLegacyPasswordHashes(\n session,\n // Process 100 database entries at a time\n batchSize: 100,\n // Stop after 500 entries have been migrated\n maxMigratedEntries: 500,\n );\n\n totalMigratedPasswords += entriesMigrated;\n session.log(\n \u0027Migrated $entriesMigrated password entries, total $totalMigratedPasswords.\u0027,\n );\n\n if (entriesMigrated == 0) break;\n\n // Delay to avoid overloading the database\n await Future.delayed(Duration(seconds: 1));\n } catch (e) {\n session.log(\u0027Error migrating passwords: $e\u0027);\n }\n }\n\n session.log(\u0027Finished migrating passwords.\u0027);\n}\n```\n\n\u003c/details\u003e\n\n### How we migrate existing password hashes\nSince password hashes can\u2019t be recalculated without knowledge of the plain text password, the method in the email authentication module applies the new algorithm to the already stored password hashes.\n\nWhen the affected users later authenticate, their password hash will be calculated using both algorithms in tandem. If the authentication is accepted, the stored password hash will be updated to only use the new algorithm so that further authentication only needs to run the new algorithm.\n\n### Impact\nAll versions of `serverpod_auth_server` pre `1.2.6`\n\n### Patches\nUpgrading to version `1.2.6` resolves this issue.\n",
"id": "GHSA-r75m-26cq-mjxc",
"modified": "2024-03-28T17:53:42Z",
"published": "2024-03-28T17:53:42Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/serverpod/serverpod/security/advisories/GHSA-r75m-26cq-mjxc"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-29886"
},
{
"type": "WEB",
"url": "https://github.com/serverpod/serverpod/commit/a78b9e9f1de74d1300633a122b6cc0f064139ad6"
},
{
"type": "PACKAGE",
"url": "https://github.com/serverpod/serverpod"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N",
"type": "CVSS_V3"
}
],
"summary": "Serverpod improved security for stored password hashes"
}
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.