Skip to content

Better error handling for circular references in custom auth tokens #1247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

import { newError } from './error'
import { stringify } from './json'

/**
* @property {function(username: string, password: string, realm: ?string)} basic the function to create a
* basic authentication token.
Expand Down Expand Up @@ -74,6 +77,11 @@ const auth = {
output.realm = realm
}
if (isNotEmpty(parameters)) {
try {
stringify(parameters)
} catch (e) {
throw newError('Circular references in custom auth token parameters', undefined, e)
}
output.parameters = parameters
}
return output
Expand Down
6 changes: 6 additions & 0 deletions packages/core/test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
import auth from '../src/auth'

describe('auth', () => {
test('.custom() should crash with circular references in parameters', () => {
const params = { a: '', b: {} }
params.b = params
expect(() => auth.custom('test', 'pass', 'realm', 'scheme', params)).toThrow('Circular references in custom auth token parameters')
})

test('.bearer()', () => {
expect(auth.bearer('==Qyahiadakkda')).toEqual({ scheme: 'bearer', credentials: '==Qyahiadakkda' })
})
Expand Down
8 changes: 8 additions & 0 deletions packages/neo4j-driver-deno/lib/core/auth.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.