Skip to content

Commit a493d57

Browse files
migrate to mongodb-js/saslprep
1 parent 1f228db commit a493d57

File tree

6 files changed

+17
-128
lines changed

6 files changed

+17
-128
lines changed

foo.mermaid

Lines changed: 0 additions & 26 deletions
This file was deleted.

package-lock.json

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
},
2727
"dependencies": {
2828
"bson": "^5.4.0",
29-
"mongodb-connection-string-url": "^2.6.0"
30-
},
31-
"optionalDependencies": {
32-
"saslprep": "^1.0.3"
29+
"mongodb-connection-string-url": "^2.6.0",
30+
"@mongodb-js/saslprep": "^1.1.0"
3331
},
3432
"peerDependencies": {
3533
"@aws-sdk/credential-providers": "^3.188.0",

src/cmap/auth/scram.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { saslprep } from '@mongodb-js/saslprep';
12
import * as crypto from 'crypto';
23
import { promisify } from 'util';
34

45
import { Binary, type Document } from '../../bson';
5-
import { saslprep } from '../../deps';
66
import {
77
MongoInvalidArgumentError,
88
MongoMissingCredentialsError,
99
MongoRuntimeError
1010
} from '../../error';
11-
import { emitWarning, ns } from '../../utils';
11+
import { ns } from '../../utils';
1212
import type { HandshakeDocument } from '../connect';
1313
import { type AuthContext, AuthProvider } from './auth_provider';
1414
import type { MongoCredentials } from './mongo_credentials';
@@ -34,12 +34,6 @@ class ScramSHA extends AuthProvider {
3434
if (!credentials) {
3535
throw new MongoMissingCredentialsError('AuthContext must provide credentials.');
3636
}
37-
if (
38-
cryptoMethod === 'sha256' &&
39-
('kModuleError' in saslprep || typeof saslprep !== 'function')
40-
) {
41-
emitWarning('Warning: no saslprep library specified. Passwords will not be sanitized');
42-
}
4337

4438
const nonce = await this.randomBytesAsync(24);
4539
// store the nonce for later use
@@ -141,13 +135,8 @@ async function continueScramConversation(
141135
const username = cleanUsername(credentials.username);
142136
const password = credentials.password;
143137

144-
let processedPassword;
145-
if (cryptoMethod === 'sha256') {
146-
processedPassword =
147-
'kModuleError' in saslprep || typeof saslprep !== 'function' ? password : saslprep(password);
148-
} else {
149-
processedPassword = passwordDigest(username, password);
150-
}
138+
const processedPassword =
139+
cryptoMethod === 'sha256' ? saslprep(password) : passwordDigest(username, password);
151140

152141
const payload = Buffer.isBuffer(response.payload)
153142
? new Binary(response.payload)

src/deps.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,6 @@ export function getSocks(): SocksLib | { kModuleError: MongoMissingDependencyErr
189189
}
190190
}
191191

192-
export let saslprep: typeof import('saslprep') | { kModuleError: MongoMissingDependencyError } =
193-
makeErrorModule(
194-
new MongoMissingDependencyError(
195-
'Optional module `saslprep` not found.' +
196-
' Please install it to enable Stringprep Profile for User Names and Passwords'
197-
)
198-
);
199-
200-
try {
201-
// Ensure you always wrap an optional require in the try block NODE-3199
202-
saslprep = require('saslprep');
203-
} catch {} // eslint-disable-line
204-
205192
interface AWS4 {
206193
/**
207194
* Created these inline types to better assert future usage of this API

test/integration/auth/scram_sha_256.test.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)