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

[v16] check that an FQDN belongs to a known app before redirecting to it #44188

Merged
merged 1 commit into from
Jul 16, 2024
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
20 changes: 14 additions & 6 deletions web/packages/teleport/src/AppLauncher/AppLauncher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ describe('app launcher path is properly formed', () => {
global.fetch = jest.fn(() => Promise.resolve({})) as jest.Mock;
jest.spyOn(api, 'get').mockResolvedValue({});
jest.spyOn(api, 'post').mockResolvedValue({});
jest.spyOn(service, 'getAppFqdn').mockResolvedValue({
fqdn: 'grafana.localhost',
});
jest.spyOn(service, 'createAppSession').mockResolvedValue({
cookieValue: 'cookie-value',
subjectCookieValue: 'subject-cookie-value',
Expand Down Expand Up @@ -115,7 +118,10 @@ describe('app launcher path is properly formed', () => {
);
});

test('arn is url decoded', () => {
test('arn is url decoded', async () => {
jest.spyOn(service, 'getAppFqdn').mockResolvedValue({
fqdn: 'test-app.test.teleport',
});
jest.spyOn(service, 'createAppSession');

const launcherPath =
Expand All @@ -132,11 +138,13 @@ describe('app launcher path is properly formed', () => {
</Router>
);

expect(service.createAppSession).toHaveBeenCalledWith({
fqdn: 'test-app.test.teleport',
clusterId: 'test.teleport',
publicAddr: 'test-app.test.teleport',
arn: 'arn:aws:iam::joe123:role/EC2FullAccess',
await waitFor(() => {
expect(service.createAppSession).toHaveBeenCalledWith({
fqdn: 'test-app.test.teleport',
clusterId: 'test.teleport',
publicAddr: 'test-app.test.teleport',
arn: 'arn:aws:iam::joe123:role/EC2FullAccess',
});
});
});
});
15 changes: 15 additions & 0 deletions web/packages/teleport/src/AppLauncher/AppLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ export function AppLauncher() {
const port = location.port ? `:${location.port}` : '';

try {
// Attempt to resolve the fqdn of the app, if we can't then an error
// will be returned preventing a redirect to a potentially arbitrary
// address. Compare the resolved fqdn with the one that was passed,
// if they don't match then the public address was used to find the
// resolved fqdn, and the passed fdqn isn't valid.
const resolvedApp = await service.getAppFqdn({
fqdn: params.fqdn,
clusterId: params.clusterId,
publicAddr: params.publicAddr,
arn: params.arn,
});
if (resolvedApp.fqdn !== params.fqdn) {
throw Error(`Failed to match applications with FQDN ${params.fqdn}`);
}

let path = '';
if (queryParams.has('path')) {
path = queryParams.get('path');
Expand Down
Loading