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

LPD-40723 Rework initial SF rule to account for the <liferay-ui:csp> tag #4605

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ if (Validator.isNotNull(backURL)) {

<c:if test="<%= Validator.isNotNull(curBackgroundTask.getStatusMessage()) %>">
<div class="background-task-status-row h6">
<liferay:csp>
<liferay-ui:csp>
<a class="details-link" href="javascript:void(0);" onclick="<portlet:namespace />viewBackgroundTaskDetails(<%= curBackgroundTask.getBackgroundTaskId() %>);">
<liferay-ui:message key="see-more-details" />
</a>
</liferay:csp>
</liferay-ui:csp>
</div>

<div class="background-task-status-message hide" id="<portlet:namespace />backgroundTaskStatusMessage<%= curBackgroundTask.getBackgroundTaskId() %>">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ private void _checkIllegalAttributes(
String lowerCaseContent) {

List<String> ignoredTagPrefixes = new ArrayList<>();
String liferayUiCspTagOpen = StringPool.BLANK;
String liferayUiCspTagClose = StringPool.BLANK;

if (fileName.endsWith(".ftl")) {
ignoredTagPrefixes = getAttributeValues(
_IGNORED_FTL_TAG_PREFIXES_KEY, absolutePath);
liferayUiCspTagOpen = "<@liferay_ui.csp>";
liferayUiCspTagClose = "</@liferay_ui.csp>";
}
else if (fileName.endsWith(".jsp") || fileName.endsWith(".jspf") ||
fileName.endsWith(".jspx")) {

ignoredTagPrefixes = getAttributeValues(
_IGNORED_JSP_TAG_PREFIXES_KEY, absolutePath);
liferayUiCspTagOpen = "<liferay-ui:csp>";
liferayUiCspTagClose = "</liferay-ui:csp>";
}

if (ListUtil.isEmpty(ignoredTagPrefixes)) {
Expand Down Expand Up @@ -99,6 +105,15 @@ else if (fileName.endsWith(".jsp") || fileName.endsWith(".jspf") ||
}
}

String previousPart = content.substring(0, tagStartPosition);

int y = previousPart.lastIndexOf(liferayUiCspTagClose);
int z = previousPart.lastIndexOf(liferayUiCspTagOpen);

if (z > y) {
continue outerLoop;
}

addMessage(
fileName,
"Tag attribute \"" + illegalAttributeName +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@
<check name="CSPComplianceCheck">
<category name="Bug Prevention" />
<description name="Checks code to prevent common CSP related pitfalls." />
<property name="enabled" value="false" />
</check>
<check name="FTLEmptyLinesCheck">
<category name="Styling" />
Expand Down Expand Up @@ -1091,7 +1090,6 @@
<check name="CSPComplianceCheck">
<category name="Bug Prevention" />
<description name="Checks code to prevent common CSP related pitfalls." />
<property name="enabled" value="false" />
</check>
<check name="EmptyCollectionCheck">
<category name="Styling" />
Expand Down