Skip to content
Open

Master #1338

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
15 changes: 13 additions & 2 deletions public/static/oidc-callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@
return oidcUserManager.signinRedirectCallback();
})
.then((user) => {
const redirectTo = user.state;
window.location.href = redirectTo && isUrlSaveForRedirect(redirectTo) ? redirectTo : "../";
const redirectTo = user.state;
// Verhindere Redirect auf Callback- oder Login-Seite
const forbiddenRedirects = [window.location.pathname, '/login', 'oidc-callback.html'];
Copy link
Member

Choose a reason for hiding this comment

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

Preventing a redirect to /login would break OIDC authentication entirely, since that is where the actual authentication with DT happens:

// oidcUser will only be set when coming from oidc-callback.html
if (oidcUser === null) {
return;
}
// Exchange OAuth2 Access Token for a JWT issued by Dependency-Track
const url = this.$api.BASE_URL + '/' + this.$api.URL_USER_OIDC_LOGIN;
const requestBody = {
accessToken: oidcUser.access_token,
idToken: oidcUser.id_token,
};
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};

Was this fix tested?

function isRedirectAllowed(url) {
if (!url) return false;
try {
const parsedUrl = new URL(url, window.location.origin);
return !forbiddenRedirects.some(f => parsedUrl.pathname.endsWith(f));
} catch (e) {
return false;
}
}
window.location.href = redirectTo && isUrlSaveForRedirect(redirectTo) && isRedirectAllowed(redirectTo) ? redirectTo : "../";
})
.catch((err) => {
console.log(err);
Expand Down