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

AdminActivityLogTableRow: fix bug in displaying error message #8608 #8609

Merged
merged 7 commits into from
Mar 8, 2018

Conversation

tran-tien-dat
Copy link
Contributor

Fixes #8608

Outline of Solution

Use the correct function to retrieve the response result in a log message.

@@ -145,7 +146,7 @@ public String getLogId() {
}

public String getActionName() {
return activityLog.getActionName();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename to getDisplayedActionName and move the method above the Forwarding activityLog methods as it should belong to Enhancement to the fields

@@ -157,7 +158,7 @@ public boolean getIsMasqueradeUserRole() {
}

public String getMessage() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

public void testSanitizeForLogMessage() {
assertNull("should return null if given null", SanitizationHelper.sanitizeForLogMessage(null));

String unsanitized = "<span class=\"text-danger\"> A <span class=\"bold\">typical</span> log message <br>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Some HTML elements with other class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently i'm only allowing bold and text-danger as that's what i found the log messages to be using. Other classes will be escaped.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is exactly I am asking for, to test that scenario also and make sure it works

return null;
}
return unsanitizedString
.replaceAll("<(?!(/?(span( class=\"(bold|text-danger)\")?|br)>))", "&lt;")
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe there is a more readable way to write this. Check richTextPolicy in SanitizationHelper

Copy link
Contributor Author

@tran-tien-dat tran-tien-dat Mar 7, 2018

Choose a reason for hiding this comment

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

richTextPolicy uses the OWASP sanitization library for Java which will remove disallowed elements instead of escaping them. Hence I had to write my own regular expression to do this. I went for conciseness here. The more readable way would be to list out all the full-string possibilities, i.e. something like

"<(?!(span class=\"bold\">|span class=\"text-danger\">|/span>|br>))"

Do you think we should use this form instead?

@xpdavid xpdavid added the s.Ongoing The PR is being worked on by the author(s) label Mar 7, 2018
@xpdavid xpdavid self-assigned this Mar 7, 2018
assertNull("should return null if given null", SanitizationHelper.sanitizeForLogMessage(null));

String unsanitized = "<span class=\"text-danger\"> A <span class=\"bold\">typical</span> log message <br>"
+ " It contains some <script>dangerous</script> elements </span>";
Copy link
Contributor

Choose a reason for hiding this comment

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

Add ' also?

Copy link
Contributor

@xpdavid xpdavid Mar 7, 2018

Choose a reason for hiding this comment

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

This is to make sure ' is also sanitised.

Opps. See your changes already :P


unsanitized = "Hmm. <span class=\"text-info\"> How about this? </span> and <span> this</span>";
correctSanitized =
"Hmm. &lt;span class=&quot;text-info&quot;&gt; How about this? </span> and <span> this</span>";
Copy link
Contributor

@xpdavid xpdavid Mar 7, 2018

Choose a reason for hiding this comment

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

The html tag is not well-formed :(
But seems no better solution for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, this is ugly but there's no simple solution for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can be fixed together with sub-issue in #6502 - give a standard way to generate statusToAdmin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, the log message should just contain plaintext but have a predefined form based on the result type. Then we can sanitize the whole log message, and use the predefined form to parse and format the message according to what we want.

unsanitized = "Hmm. <span class=\"text-info\"> How about this? </span> and <span> this</span>";
correctSanitized =
"Hmm. &lt;span class=&quot;text-info&quot;&gt; How about this? </span> and <span> this</span>";
assertEquals("Should escape <span class=\"text-danger\">, <span class=\"bold\"> and <br>",
Copy link
Contributor

Choose a reason for hiding this comment

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

The message is bit confusing
Should escape tag other than <span class=\"text-danger\">, <span class=\"bold\"> and <br> right?

Copy link
Contributor Author

@tran-tien-dat tran-tien-dat Mar 7, 2018

Choose a reason for hiding this comment

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

My mistake. Copy pasted from above and didn't edit properly

Copy link
Contributor

@xpdavid xpdavid left a comment

Choose a reason for hiding this comment

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

LGTM!

Tested and the measure works

@xpdavid xpdavid added s.FinalReview The PR is ready for final review and removed s.Ongoing The PR is being worked on by the author(s) labels Mar 7, 2018
@xpdavid xpdavid requested a review from damithc March 7, 2018 16:41
@damithc damithc added s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging and removed s.FinalReview The PR is ready for final review labels Mar 8, 2018
@xpdavid xpdavid merged commit 7759101 into TEAMMATES:master Mar 8, 2018
@whipermr5 whipermr5 added this to the V6.4.0 milestone Mar 8, 2018
@tran-tien-dat tran-tien-dat deleted the fix-log branch March 8, 2018 04:17
@whipermr5 whipermr5 added e.2 c.Bug Bug/defect report labels Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c.Bug Bug/defect report s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants