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
[#8779] AccountAttributes: Remove HTML sanitization before saving for googleId, name, institute #9368
Conversation
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.
Yes, we might not need a script.
@@ -181,9 +181,9 @@ public String getJsonString() { | |||
|
|||
@Override | |||
public void sanitizeForSaving() { | |||
this.googleId = SanitizationHelper.sanitizeForHtml(googleId); |
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.
Should use SanitizationHelper.sanitizeGoogleId
?
@@ -181,9 +181,9 @@ public String getJsonString() { | |||
|
|||
@Override | |||
public void sanitizeForSaving() { | |||
this.googleId = SanitizationHelper.sanitizeForHtml(googleId); | |||
this.name = SanitizationHelper.sanitizeForHtml(name); |
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.
SanitizationHelper.sanitizeName
?
@@ -181,9 +181,9 @@ public String getJsonString() { | |||
|
|||
@Override | |||
public void sanitizeForSaving() { | |||
this.googleId = SanitizationHelper.sanitizeForHtml(googleId); | |||
this.name = SanitizationHelper.sanitizeForHtml(name); | |||
this.institute = SanitizationHelper.sanitizeForHtml(institute); |
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.
SanitizationHelper.sanitizeName
maybe?
Done, ready for review. I used SanitizationHelper.sanitizeTitle for institute sanitization (based on AccountAttributes's Builder build() method.) |
package.json
Outdated
@@ -44,7 +44,7 @@ | |||
}, | |||
"devDependencies": { | |||
"@angular-builders/jest": "~7.1.2", | |||
"@angular-devkit/build-angular": "~0.11.4", |
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.
Not relevant change?
@@ -95,9 +94,9 @@ public void testSanitizeForSaving() { | |||
AccountAttributes expectedAccount = createAccountAttributesToSanitize(); | |||
actualAccount.sanitizeForSaving(); | |||
|
|||
assertEquals(SanitizationHelper.sanitizeForHtml(expectedAccount.googleId), actualAccount.googleId); |
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.
So your tests should also reflect the changes?
e.g. Having some values that need to be sanitised and test whether the actualAccount.sanitizeForSaving();
work or not?
Sorry, forgot about the tests. Interestingly, this means that the tests would have passed no matter what, because the Builder in AccountAttributes sanitized the results when building the object. I've changed the email test to add the single quote and added whitespace around all the values since the sanitization code is effectively just trimming the values. Ready for review. |
@@ -92,6 +92,10 @@ public AccountAttributes build() { | |||
return accountAttributes; | |||
} | |||
|
|||
public AccountAttributes buildWithoutSanitizing() { |
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.
I don't think it is a good practice to introduce this method in production code just for testing.
assertEquals(SanitizationHelper.sanitizeForHtml(expectedAccount.name), actualAccount.name); | ||
assertEquals(SanitizationHelper.sanitizeForHtml(expectedAccount.institute), actualAccount.institute); | ||
assertEquals(SanitizationHelper.sanitizeGoogleId(expectedAccount.googleId), actualAccount.googleId); | ||
assertEquals(SanitizationHelper.sanitizeName(expectedAccount.name), actualAccount.name); |
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.
Interestingly, this means that the tests would have passed no matter what, because the Builder in AccountAttributes sanitized the results when building the object.
If that is the case. Maybe we can just do assertEquals(expectedAccount.name, actualAccount.name)
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.
I'm not quite sure I understand how that solves the problem. Since build sanitizes all the fields, both expectedAccount and actualAccount will have the same values. Checking equality would only verify that running sanitizeForSaving on sanitized values doesn't change the values at all.
Perhaps the method createAccountAttributesToSanitize could just modify the values directly? So something like:
private AccountAttributes createAccountAttributesToSanitize() {
AccountAttributes unsanitizedAttributes = AccountAttributes.builder().build();
unsanitizedAttributes.googleId = " google'Id@gmail.com\t";
unsanitizedAttributes.name = "'name'\n\n";
unsanitizedAttributes.institute = "\\\t\n/";
unsanitizedAttributes.email = "&<email>&\n";
unsanitizedAttributes.isInstructor = true;
return unsanitizedAttributes;
}
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.
Cool. We can do that.
Ok, ready for review. |
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.
Some comment on test data selection.
unsanitizedAttributes.googleId = " google'Id@gmail.com\t"; | ||
unsanitizedAttributes.name = "'name'\n\n"; | ||
unsanitizedAttributes.institute = "\\\t\n/"; | ||
unsanitizedAttributes.email = "&<email>&\n"; |
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.
I think we should change this to a valid email address.
|
||
AccountAttributes unsanitizedAttributes = AccountAttributes.builder().build(); | ||
unsanitizedAttributes.googleId = " google'Id@gmail.com\t"; | ||
unsanitizedAttributes.name = "'name'\n\n"; |
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.
There should be some extra space inside name in order to make sure sanitizeName
is doing the job? 'name'\n\n
?
AccountAttributes unsanitizedAttributes = AccountAttributes.builder().build(); | ||
unsanitizedAttributes.googleId = " google'Id@gmail.com\t"; | ||
unsanitizedAttributes.name = "'name'\n\n"; | ||
unsanitizedAttributes.institute = "\\\t\n/"; |
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.
Same for institute.
Ok, test data modified, whitespace added to the middle of the strings. Ready for review. |
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.
LGTM!
Fixes #8779
Outline of Solution
Basically just removed the sanitization in AccountAttributes and updated tests. I have tested with single quotes in the email (as per #8774) and it works.
I'm not sure if I need to write a migration script, let me know if I need to. Based on my checks, if there was something to be migrated, it wouldn't have made it to the database anyway because the application would have just rejected it.
Ready for review.