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

[#11586] Remove trailing @gmail.com when checking for user ID equality #11923

Merged
merged 1 commit into from
Aug 3, 2022
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
3 changes: 2 additions & 1 deletion src/main/java/teammates/ui/webapi/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void setLogsProcessor(LogsProcessor logsProcessor) {
*/
public void checkAccessControl() throws UnauthorizedAccessException {
String userParam = getRequestParamValue(Const.ParamsNames.USER_ID);
if (userInfo != null && userParam != null && !userInfo.isAdmin && !userInfo.id.equals(userParam)) {
if (userInfo != null && userParam != null && !userInfo.isAdmin
&& !userInfo.id.replaceFirst("@gmail.com$", "").equals(userParam.replaceFirst("@gmail.com$", ""))) {
throw new UnauthorizedAccessException("User " + userInfo.id
+ " is trying to masquerade as " + userParam + " without admin permission.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void checkAccessControlForStudentFeedbackSubmission(
if (userInfo == null) {
// Student is associated to a google ID; even if registration key is passed, do not allow access
throw new UnauthorizedAccessException("Login is required to access this feedback session");
} else if (!userInfo.id.equals(student.getGoogleId())) {
} else if (!userInfo.id.replaceFirst("@gmail.com$", "")
.equals(student.getGoogleId().replaceFirst("@gmail.com$", ""))) {
// Logged in student is not the same as the student registered for the given key, do not allow access
throw new UnauthorizedAccessException("You are not authorized to access this feedback session");
}
Expand Down Expand Up @@ -134,7 +135,8 @@ void checkAccessControlForInstructorFeedbackSubmission(
if (userInfo == null) {
// Instructor is associated to a google ID; even if registration key is passed, do not allow access
throw new UnauthorizedAccessException("Login is required to access this feedback session");
} else if (!userInfo.id.equals(instructor.getGoogleId())) {
} else if (!userInfo.id.replaceFirst("@gmail.com$", "")
.equals(instructor.getGoogleId().replaceFirst("@gmail.com$", ""))) {
// Logged in instructor is not the same as the instructor registered for the given key,
// do not allow access
throw new UnauthorizedAccessException("You are not authorized to access this feedback session");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
throw new UnauthorizedAccessException("Student privilege is required to update this resource.");
}
String googleId = getNonNullRequestParamValue(Const.ParamsNames.STUDENT_ID);
if (!userInfo.id.equals(googleId)) {
if (!userInfo.id.replaceFirst("@gmail.com$", "").equals(googleId.replaceFirst("@gmail.com$", ""))) {
throw new UnauthorizedAccessException("You are not authorized to delete this student's profile.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public JsonResult execute() {
isUsed = true;
// If the registration key has been used to register, the logged in user needs to match
// Block access to not logged in user and mismatched user
isAllowedAccess = userInfo != null && googleId.equals(userInfo.id);
isAllowedAccess = userInfo != null && googleId.replaceFirst("@gmail.com$", "")
.equals(userInfo.id.replaceFirst("@gmail.com$", ""));
}
}

Expand Down