Skip to content

Commit ae16fa3

Browse files
authored
Better error handling for circular references in custom auth tokens (#1247)
It is quite easy for a user to provide an object with a circular reference in the parameters of a custom auth token, despite this being impossible to send over Bolt. The current handling for this error is not very clear, this PR ensures an understandable error is thrown
1 parent d7ad517 commit ae16fa3

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

packages/core/src/auth.ts

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { newError } from './error'
19+
import { stringify } from './json'
20+
1821
/**
1922
* @property {function(username: string, password: string, realm: ?string)} basic the function to create a
2023
* basic authentication token.
@@ -74,6 +77,11 @@ const auth = {
7477
output.realm = realm
7578
}
7679
if (isNotEmpty(parameters)) {
80+
try {
81+
stringify(parameters)
82+
} catch (e) {
83+
throw newError('Circular references in custom auth token parameters', undefined, e)
84+
}
7785
output.parameters = parameters
7886
}
7987
return output

packages/core/test/auth.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import auth from '../src/auth'
1818
import { cacheKey } from '../src/internal/auth-util'
1919

2020
describe('auth', () => {
21+
test('.custom() should crash with circular references in parameters', () => {
22+
const params = { a: '', b: {} }
23+
params.b = params
24+
expect(() => auth.custom('test', 'pass', 'realm', 'scheme', params)).toThrow('Circular references in custom auth token parameters')
25+
})
26+
2127
test('.bearer()', () => {
2228
expect(auth.bearer('==Qyahiadakkda')).toEqual({ scheme: 'bearer', credentials: '==Qyahiadakkda' })
2329
})

packages/neo4j-driver-deno/lib/core/auth.ts

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)