Skip to content
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

Add a null check to getMfaChallengeResponse #50570

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function ChangePasswordWizard({
const reauthState = useReAuthenticate({
challengeScope: MfaChallengeScope.CHANGE_PASSWORD,
onMfaResponse: async mfaResponse =>
setWebauthnResponse(mfaResponse.webauthn_response),
setWebauthnResponse(mfaResponse?.webauthn_response),
});

const [reauthMethod, setReauthMethod] = useState<ReauthenticationMethod>();
Expand Down
6 changes: 3 additions & 3 deletions web/packages/teleport/src/lib/term/tty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ class Tty extends EventEmitterMfaSender {
this.socket.send(bytearray.buffer);
}

sendChallengeResponse(data: MfaChallengeResponse) {
sendChallengeResponse(resp: MfaChallengeResponse) {
// we want to have the backend listen on a single message type
// for any responses. so our data will look like data.webauthn, data.sso, etc
// but to be backward compatible, we need to still spread the existing webauthn only fields
// as "top level" fields so old proxies can still respond to webauthn challenges.
// in 19, we can just pass "data" without this extra step
// TODO (avatus): DELETE IN 19.0.0
const backwardCompatibleData = {
...data.webauthn_response,
...data,
...resp?.webauthn_response,
...resp,
};
const encoded = this._proto.encodeChallengeResponse(
JSON.stringify(backwardCompatibleData)
Expand Down
6 changes: 4 additions & 2 deletions web/packages/teleport/src/services/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const auth = {
.then(res => {
const request = {
action: 'accept',
webauthnAssertionResponse: res.webauthn_response,
webauthnAssertionResponse: res?.webauthn_response,
};

return api.put(cfg.getHeadlessSsoPath(transactionId), request);
Expand Down Expand Up @@ -282,6 +282,8 @@ const auth = {
mfaType?: DeviceType,
totpCode?: string
): Promise<MfaChallengeResponse> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps?

Suggested change
): Promise<MfaChallengeResponse> {
): Promise<MfaChallengeResponse|undefined> {

if (!challenge) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return undefined here, but null on line 315. Can we be more consistent and explicit about the behavior?


// TODO(Joerger): If mfaType is not provided by a parent component, use some global context
// to display a component, similar to the one used in useMfa. For now we just default to
// whichever method we can succeed with first.
Expand Down Expand Up @@ -439,7 +441,7 @@ const auth = {
return auth
.getMfaChallenge({ scope, allowReuse, isMfaRequiredRequest }, abortSignal)
.then(challenge => auth.getMfaChallengeResponse(challenge, 'webauthn'))
.then(res => res.webauthn_response);
.then(res => res?.webauthn_response);
},

getMfaChallengeResponseForAdminAction(allowReuse?: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion web/packages/teleport/src/services/mfa/makeMfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function parseMfaChallengeJson(
!challenge.webauthn_challenge &&
!challenge.totp_challenge
) {
return null;
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the return type of this function be MfaAuthenciateChallenge | undefined?

We don't have strict null checks enabled right now, but if we did this would not compile as-is.

}

// WebAuthn challenge contains Base64URL(byte) fields that needs to
Expand Down
Loading