mirror of
https://github.com/standardnotes/server
synced 2026-01-16 20:04:32 -05:00
feat(auth): add configuring u2f expect origin
This commit is contained in:
@@ -71,3 +71,4 @@ WEB_SOCKET_CONNECTION_TOKEN_SECRET=
|
||||
# (Optional) U2F Setup
|
||||
U2F_RELYING_PARTY_ID=
|
||||
U2F_RELYING_PARTY_NAME=
|
||||
U2F_EXPECTED_ORIGIN=
|
||||
|
||||
@@ -462,6 +462,9 @@ export class ContainerConfigLoader {
|
||||
container
|
||||
.bind(TYPES.U2F_RELYING_PARTY_ID)
|
||||
.toConstantValue(env.get('U2F_RELYING_PARTY_ID', true) ?? 'standardnotes.com')
|
||||
container
|
||||
.bind(TYPES.U2F_EXPECTED_ORIGIN)
|
||||
.toConstantValue(env.get('U2F_EXPECTED_ORIGIN', true) ?? 'https://app.standardnotes.com')
|
||||
// Services
|
||||
container.bind<UAParser>(TYPES.DeviceDetector).toConstantValue(new UAParser())
|
||||
container.bind<SessionService>(TYPES.SessionService).to(SessionService)
|
||||
@@ -575,6 +578,7 @@ export class ContainerConfigLoader {
|
||||
container.get(TYPES.AuthenticatorRepository),
|
||||
container.get(TYPES.AuthenticatorChallengeRepository),
|
||||
container.get(TYPES.U2F_RELYING_PARTY_ID),
|
||||
container.get(TYPES.U2F_EXPECTED_ORIGIN),
|
||||
),
|
||||
)
|
||||
container
|
||||
@@ -592,6 +596,7 @@ export class ContainerConfigLoader {
|
||||
container.get(TYPES.AuthenticatorRepository),
|
||||
container.get(TYPES.AuthenticatorChallengeRepository),
|
||||
container.get(TYPES.U2F_RELYING_PARTY_ID),
|
||||
container.get(TYPES.U2F_EXPECTED_ORIGIN),
|
||||
),
|
||||
)
|
||||
container
|
||||
|
||||
@@ -96,6 +96,7 @@ const TYPES = {
|
||||
SESSION_TRACE_DAYS_TTL: Symbol.for('SESSION_TRACE_DAYS_TTL'),
|
||||
U2F_RELYING_PARTY_ID: Symbol.for('U2F_RELYING_PARTY_ID'),
|
||||
U2F_RELYING_PARTY_NAME: Symbol.for('U2F_RELYING_PARTY_NAME'),
|
||||
U2F_EXPECTED_ORIGIN: Symbol.for('U2F_EXPECTED_ORIGIN'),
|
||||
// use cases
|
||||
AuthenticateUser: Symbol.for('AuthenticateUser'),
|
||||
AuthenticateRequest: Symbol.for('AuthenticateRequest'),
|
||||
|
||||
@@ -17,6 +17,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => {
|
||||
authenticatorRepository,
|
||||
authenticatorChallengeRepository,
|
||||
'standardnotes.com',
|
||||
'https://app.standardnotes.com',
|
||||
)
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -11,6 +11,7 @@ export class VerifyAuthenticatorAuthenticationResponse implements UseCaseInterfa
|
||||
private authenticatorRepository: AuthenticatorRepositoryInterface,
|
||||
private authenticatorChallengeRepository: AuthenticatorChallengeRepositoryInterface,
|
||||
private relyingPartyId: string,
|
||||
private expectedOrigin: string,
|
||||
) {}
|
||||
|
||||
async execute(dto: VerifyAuthenticatorAuthenticationResponseDTO): Promise<Result<boolean>> {
|
||||
@@ -40,7 +41,7 @@ export class VerifyAuthenticatorAuthenticationResponse implements UseCaseInterfa
|
||||
verification = await verifyAuthenticationResponse({
|
||||
response: dto.authenticatorResponse,
|
||||
expectedChallenge: authenticatorChallenge.props.challenge.toString(),
|
||||
expectedOrigin: `https://${this.relyingPartyId}`,
|
||||
expectedOrigin: this.expectedOrigin,
|
||||
expectedRPID: this.relyingPartyId,
|
||||
authenticator: {
|
||||
counter: authenticator.props.counter,
|
||||
|
||||
@@ -17,6 +17,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
|
||||
authenticatorRepository,
|
||||
authenticatorChallengeRepository,
|
||||
'standardnotes.com',
|
||||
'https://app.standardnotes.com',
|
||||
)
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -11,6 +11,7 @@ export class VerifyAuthenticatorRegistrationResponse implements UseCaseInterface
|
||||
private authenticatorRepository: AuthenticatorRepositoryInterface,
|
||||
private authenticatorChallengeRepository: AuthenticatorChallengeRepositoryInterface,
|
||||
private relyingPartyId: string,
|
||||
private expectedOrigin: string,
|
||||
) {}
|
||||
|
||||
async execute(dto: VerifyAuthenticatorRegistrationResponseDTO): Promise<Result<boolean>> {
|
||||
@@ -35,7 +36,7 @@ export class VerifyAuthenticatorRegistrationResponse implements UseCaseInterface
|
||||
verification = await verifyRegistrationResponse({
|
||||
response: dto.attestationResponse,
|
||||
expectedChallenge: authenticatorChallenge.props.challenge.toString(),
|
||||
expectedOrigin: `https://${this.relyingPartyId}`,
|
||||
expectedOrigin: this.expectedOrigin,
|
||||
expectedRPID: this.relyingPartyId,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user