-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pentest #1566
Pentest #1566
Changes from 87 commits
4ec9da8
a29a5ef
1fc58a5
e479739
ec0318f
bcae194
1ba363c
dae1ad5
21b496c
906b2d3
80db87f
e98d55b
124562a
71b385a
2d1d3ec
46dd3a5
ee2b4d7
f13baad
bdb4aa4
49bdbc5
43a31f2
296c703
dfb8b58
1a063d6
b3e2b3c
1ee9531
9c2cf4b
482b372
241359a
d44ff81
6053e1f
3c6114b
11a3f36
a3910d0
27602b5
cddf88a
ba77a1a
196e274
38096e8
402cef2
429365a
00e0c26
e6fda5e
e23b30b
05e73da
4749749
c97d0d5
f3b26a8
7f05351
38572ef
680f6a6
d80e3a6
c57e21c
046a1ee
946c06f
eee0331
c2a1904
3a6e6e8
2f3d84e
4605e2a
5246834
615a44a
cf6a916
d23bb62
b1990bd
bff86f0
af24ad7
9b93afc
c827c39
78e514f
15c27a2
1888c43
4bb4252
e7f3619
e7eb97b
fd8c5a5
169ec77
b97f818
2574960
fd4b0dd
943f46f
ee808f0
9c8316b
9c09938
4d16d78
8a3debe
9580202
2933f8e
81bc3d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getUser } from "../../app-api/getUser"; | ||
|
||
const handler = async (event) => { | ||
console.log("JWT claims before modification:", JSON.stringify(event)); | ||
try{ | ||
const userEmail = event.request.userAttributes.email; | ||
const user = await getUser(userEmail); | ||
const roles = []; | ||
for (const role of user.roleList) { | ||
roles.push(role.role) | ||
} | ||
event.response = event.response || {}; | ||
event.response.claimsOverrideDetails = event.response.claimsOverrideDetails || {}; | ||
event.response.claimsOverrideDetails.claimsToAddOrOverride = event.response.claimsOverrideDetails.claimsToAddOrOverride || {}; | ||
|
||
// Example of adding roles dynamically from DynamoDB to the JWT claims | ||
event.response.claimsOverrideDetails.claimsToAddOrOverride['custom:user_roles'] = JSON.stringify(roles); // Add user roles | ||
} catch(e) { | ||
console.log("error updating id token claims", e) | ||
} | ||
console.log("JWT claims after modification:", JSON.stringify(event)); | ||
return event; | ||
}; | ||
|
||
export { handler }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import AWS from "aws-sdk"; | ||
const cognito = new AWS.CognitoIdentityServiceProvider(); | ||
import { getUser } from "../../app-api/getUser"; | ||
|
||
async function updateUserAttribute(userPoolId, username, roles) { | ||
const params = { | ||
UserPoolId: userPoolId, | ||
Username: username, | ||
UserAttributes: [ | ||
{ | ||
Name: 'custom:user_roles', | ||
Value: JSON.stringify(roles) | ||
} | ||
] | ||
}; | ||
|
||
await cognito.adminUpdateUserAttributes(params).promise(); | ||
} | ||
|
||
async function processCognitoUsers() { | ||
const userPoolId = process.env.USER_POOL_ID; | ||
console.log("user pool id: ", userPoolId) | ||
let paginationToken = null; | ||
let counter = 0; | ||
let hasRolesCounter = 0; | ||
let noRolesCounter =0; | ||
do { | ||
const params = { | ||
UserPoolId: userPoolId, | ||
AttributesToGet: ['email'], | ||
PaginationToken: paginationToken | ||
}; | ||
|
||
const listUsersResponse = await cognito.listUsers(params).promise(); | ||
console.log(listUsersResponse.Users.length + " users found") | ||
|
||
for (const user of listUsersResponse.Users) { | ||
const emailAttribute = user.Attributes.find(attr => attr.Name === 'email'); | ||
if (emailAttribute) { | ||
const userEmail = emailAttribute.Value; | ||
|
||
try { | ||
const externalUser = await getUser(userEmail); | ||
let roles = [""]; | ||
let roleList; | ||
try{ | ||
roleList = externalUser.roleList; | ||
}catch(error) { | ||
noRolesCounter ++ | ||
console.log(userEmail + " has no roles"); | ||
} | ||
if (roleList && roleList.length > 0 && roleList[0] != null) { | ||
roles = externalUser.roleList.map(role => role.role); | ||
hasRolesCounter ++; | ||
} else { | ||
console.log("user parsing error for user" + userEmail) | ||
} | ||
await updateUserAttribute(userPoolId, user.Username, roles); | ||
} catch (error) { | ||
console.error(`Error processing user ${userEmail}:`, error); | ||
} | ||
} | ||
counter++; | ||
} | ||
|
||
paginationToken = listUsersResponse.PaginationToken; | ||
} while (paginationToken); | ||
console.log(counter+ "users modified, "+ hasRolesCounter + "users had roles and "+ noRolesCounter + " users had no roles") | ||
} | ||
|
||
|
||
export const main = async () => { | ||
await processCognitoUsers().catch(console.error); | ||
console.log("function complete") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,7 @@ const UserManagement = () => { | |
console.log("Error while fetching user list.", error); | ||
setAlertCode(RESPONSE_CODE[error.message]); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please discard this change as no functional changes were made to this file |
||
}, [userProfile.email, userStatus]); | ||
|
||
// Load the data from the backend. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,7 @@ const UserPage = () => { | |
const { userProfile, setUserInfo, updatePhoneNumber, userRole, userStatus } = | ||
useAppContext(); | ||
const location = useLocation(); | ||
const { userId } = useParams() ?? {}; | ||
let { userId } = useParams() ?? {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious why this change was made........might even be flagged by lint if setting with let but is never overridden.....but also probably userId is something we dont want to let get overwritten? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right I did this when I was considering how to encrypt the email/userId before Andy fixed it |
||
const [profileData, setProfileData] = useState({}); | ||
const [profileRole, setProfileRole] = useState(""); | ||
const [profileStatus, setProfileStatus] = useState(""); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for turning this into a whitelist of allowed roles!