-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Browser MFA] Add Browser MFA UI #64692
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Teleport | ||
| // Copyright (C) 2026 Gravitational, Inc. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package web | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/gravitational/trace" | ||
| "github.com/julienschmidt/httprouter" | ||
|
|
||
| mfav1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/mfa/v1" | ||
| "github.com/gravitational/teleport/lib/client" | ||
| "github.com/gravitational/teleport/lib/httplib" | ||
| ) | ||
|
|
||
| // putBrowserMFA accepts a webauthn response from a Browser MFA attempt which is | ||
| // sent to CompleteBrowserMFAChallenge for verification. Once verified a tsh | ||
| // redirect URL with an encrypted webauthn response is returned. | ||
| func (h *Handler) putBrowserMFA(_ http.ResponseWriter, r *http.Request, params httprouter.Params, sctx *SessionContext) (any, error) { | ||
| requestID := params.ByName("request_id") | ||
| if requestID == "" { | ||
| return "", trace.BadParameter("request is missing request ID") | ||
| } | ||
|
|
||
| var req client.MFAChallengeResponse | ||
| if err := httplib.ReadResourceJSON(r, &req); err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
|
|
||
| mfaResp, err := req.GetOptionalMFAResponseProtoReq() | ||
| if err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
|
|
||
| if mfaResp == nil { | ||
| return nil, trace.Errorf("mfa response is nil") | ||
| } | ||
|
|
||
| clt, err := sctx.GetClient() | ||
| if err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
|
|
||
| resp, err := clt.MFAServiceClient().CompleteBrowserMFAChallenge(r.Context(), &mfav1.CompleteBrowserMFAChallengeRequest{ | ||
| BrowserMfaResponse: &mfav1.BrowserMFAResponse{ | ||
| RequestId: requestID, | ||
| WebauthnResponse: mfaResp.GetWebauthn(), | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
|
|
||
| return resp.TshRedirectUrl, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * Teleport | ||
| * Copyright (C) 2026 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import { validateClientRedirect } from './urlValidation'; | ||
|
|
||
| describe('validateClientRedirect', () => { | ||
| test.each([ | ||
| 'http://localhost:12345?response=abc', | ||
| 'https://localhost:12345?response=abc', | ||
| 'http://127.0.0.1:12345?response=abc', | ||
| 'http://[::1]:12345?response=abc', | ||
| ])('accepts loopback URL: %s', url => { | ||
| expect(() => validateClientRedirect(url)).not.toThrow(); | ||
| }); | ||
|
|
||
| test('rejects empty URL', () => { | ||
| expect(() => validateClientRedirect('')).toThrow( | ||
| 'redirect URL must not be empty' | ||
| ); | ||
| }); | ||
|
|
||
| test('rejects non-local address', () => { | ||
| expect(() => | ||
| validateClientRedirect('http://example.com:12345?response=abc') | ||
| ).toThrow('example.com is not a valid local address'); | ||
| }); | ||
|
|
||
| test('rejects unsupported protocol', () => { | ||
| expect(() => | ||
| validateClientRedirect('ftp://localhost:12345?response=abc') | ||
| ).toThrow('ftp: is not a valid protocol'); | ||
| }); | ||
|
|
||
| test('rejects URL with credentials', () => { | ||
| expect(() => | ||
| validateClientRedirect('http://user:pass@localhost:12345?response=abc') | ||
| ).toThrow('redirect URL must not contain credentials'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * Teleport | ||
| * Copyright (C) 2026 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| const ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]']; | ||
|
|
||
| /** | ||
| * Validates that a redirect URL points to a valid local address, uses an | ||
| * allowed protocol, and does not expose URL-based credentials. | ||
| * | ||
| * This function is intended for validating client-side redirect URLs used in | ||
| * flows such as browser MFA, where the redirect target must be a local address | ||
| * (e.g. tsh, tctl etc) rather than an arbitrary external URL. | ||
| * | ||
| * Throws an error if any of the following conditions are not met: | ||
| * - The URL must not be empty. | ||
| * - The hostname must be one of the allowed local hosts: localhost, 127.0.0.1, or [::1]. | ||
| * - The protocol must be http: or https:. | ||
| * - The URL must not contain a username or password. | ||
| * | ||
| * @param url - The redirect URL string to validate. | ||
| * @throws {Error} If the URL is empty, has a disallowed host, uses an invalid protocol, | ||
| * or contains embedded credentials. | ||
| * | ||
| * @example | ||
| * validateClientRedirect('http://localhost:8080/callback') // valid, does not throw | ||
| * validateClientRedirect('http://evil.com/callback') // throws: not a valid local address | ||
| * validateClientRedirect('ftp://localhost/callback') // throws: not a valid protocol | ||
| * validateClientRedirect('http://user:pass@localhost/') // throws: must not contain credentials | ||
| */ | ||
| export function validateClientRedirect(url: string) { | ||
| if (url === '') { | ||
| throw new Error('redirect URL must not be empty'); | ||
| } | ||
|
|
||
| const parsedUrl = new URL(url); | ||
|
|
||
| if (!ALLOWED_HOSTS.includes(parsedUrl.hostname)) { | ||
| throw new Error(`${parsedUrl.hostname} is not a valid local address`); | ||
| } | ||
|
|
||
| if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') { | ||
| throw new Error(`${parsedUrl.protocol} is not a valid protocol`); | ||
| } | ||
|
|
||
| if (parsedUrl.username || parsedUrl.password) { | ||
| throw new Error('redirect URL must not contain credentials'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** | ||
| * Teleport | ||
| * Copyright (C) 2026 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import { BrowserMfaAccessDenied, BrowserMfaProcessing } from './BrowserMFA'; | ||
|
|
||
| export default { | ||
| title: 'Teleport/BrowserMFA', | ||
| }; | ||
|
|
||
| export function Processing() { | ||
| return <BrowserMfaProcessing />; | ||
| } | ||
|
|
||
| export function AccessDenied() { | ||
| return <BrowserMfaAccessDenied statusText="MFA validation failed" />; | ||
| } | ||
|
|
||
| export function AccessDeniedWithLongMessage() { | ||
| return ( | ||
| <BrowserMfaAccessDenied statusText="Your browser could not complete this authentication request. Please retry and ensure your security key or passkey is available." /> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.