Skip to content

Commit 3352314

Browse files
ayohojimmy1wu
authored andcommitted
PH67833: Update JavaScript used in OIDC session management
1 parent 0d72e7c commit 3352314

File tree

4 files changed

+21
-53
lines changed

4 files changed

+21
-53
lines changed

dev/com.ibm.ws.security.openidconnect.server/resources/scripts/enc-base64-min.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

dev/com.ibm.ws.security.openidconnect.server/resources/scripts/opiframe.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 IBM Corporation and others.
2+
* Copyright (c) 2019, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-2.0/
77
*
88
* SPDX-License-Identifier: EPL-2.0
9-
*
10-
* Contributors:
11-
* IBM Corporation - initial API and implementation
129
*******************************************************************************/
1310
window.addEventListener("message", receiveMessage, false);
1411

12+
/**
13+
* Generate a cryptographic hash of a string.
14+
*/
15+
function hash(string) {
16+
const encodedString = new TextEncoder().encode(string);
17+
return crypto.subtle.digest('SHA-256', encodedString).then((hashBuffer) => {
18+
const hashArray = Array.from(new Uint8Array(hashBuffer));
19+
const hashHex = hashArray
20+
.map((bytes) => bytes.toString(16).padStart(2, '0'))
21+
.join('');
22+
return hashHex;
23+
});
24+
}
25+
1526
/**
1627
* Get the current browser state value from the browser state cookie.
1728
*
@@ -41,13 +52,13 @@ function getBrowserState() {
4152
* @returns A Base64-encoded SHA-256 hash of the concatenation of all of the
4253
* provided arguments.
4354
*/
44-
function calculateSessionState(clientId, browserState, salt) {
55+
async function calculateSessionState(clientId, browserState, salt) {
4556
var stringToHash = clientId + '' + browserState;
4657
if (salt) {
4758
stringToHash = stringToHash + '' + salt;
4859
}
49-
var sessionState = CryptoJS.SHA256(stringToHash);
50-
sessionState = sessionState.toString(CryptoJS.enc.Base64);
60+
var sessionState = await hash(stringToHash);
61+
sessionState = btoa(sessionState);
5162
if (salt) {
5263
sessionState = sessionState + '.' + salt;
5364
}
@@ -65,7 +76,7 @@ function calculateSessionState(clientId, browserState, salt) {
6576
*
6677
* @param message
6778
*/
68-
function receiveMessage(message) {
79+
async function receiveMessage(message) {
6980
if (message.origin !== EXPECTED_ORIGIN) {
7081
console.log("Unable to complete request from " + message.origin);
7182
return;
@@ -94,7 +105,7 @@ function receiveMessage(message) {
94105
salt = stateAndSalt[1];
95106
}
96107

97-
var sessionState = calculateSessionState(clientId, browserState, salt);
108+
var sessionState = await calculateSessionState(clientId, browserState, salt);
98109

99110
var msg = "changed";
100111
// Ensure both the type and value of the two session states are equivalent

dev/com.ibm.ws.security.openidconnect.server/resources/scripts/sha256.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

dev/com.ibm.ws.security.openidconnect.server/resources/sessionMgmt.jsp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
%>
66
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
77
<!--
8-
Copyright (c) 2019 IBM Corporation and others.
8+
Copyright (c) 2019, 2025 IBM Corporation and others.
99
All rights reserved. This program and the accompanying materials
1010
are made available under the terms of the Eclipse Public License 2.0
1111
which accompanies this distribution, and is available at
1212
http://www.eclipse.org/legal/epl-2.0/
1313
1414
SPDX-License-Identifier: EPL-2.0
15-
16-
Contributors:
17-
IBM Corporation - initial API and implementation
1815
-->
1916
<html>
2017
<head>
@@ -35,8 +32,6 @@ if (expectedRpOrigin != null) {
3532
}
3633
}
3734
%>
38-
<script src="scripts/sha256.js"></script>
39-
<script src="scripts/enc-base64-min.js"></script>
4035
<script src="scripts/opiframe.js"></script>
4136
<script>
4237
var EXPECTED_ORIGIN = '<%= expectedRpOrigin %>';

0 commit comments

Comments
 (0)