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

[JENKINS-46914] [JENKINS-47885] [JENKINS-54568] JavaScript improvements #60

Merged
merged 1 commit into from
Oct 13, 2019

Conversation

daniel-beck
Copy link
Member

@daniel-beck daniel-beck commented Apr 25, 2019

  • JENKINS-54568: Make authorizationMatrix work in declarative snippet generator
  • JENKINS-46914: Better indicate implied permissions in the checkbox grid by disabling implied permission checkboxes
  • JENKINS-47885: Make node property work in Kubernetes (and old versions of Docker) plugin templates

@@ -139,13 +139,12 @@ THE SOFTWARE.
<f:helpArea />
</table>
<script>
(function() {
<!-- place master outside the DOM tree so that it won't creep into the submitted form -->
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not actually necessary. An extra row in the submission doesn't really hurt, and since principals with no permissions assigned are actually ignored server-side, not doing this will not change the result.

@daniel-beck daniel-beck changed the title [JENKINS-46914] Disable implied checkboxes [JENKINS-46914] [JENKINS-47885] [JENKINS-54568] JavaScript improvements Apr 27, 2019
@@ -187,7 +187,7 @@ public AuthorizationMatrixNodeProperty newInstance(StaplerRequest req, @Nonnull

@Override
public boolean isApplicable(Class<? extends Node> node) {
return Node.class.isAssignableFrom(node) && isApplicable();
return isApplicable();
Copy link
Member Author

Choose a reason for hiding this comment

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

This only existed as a hack to prevent Kubernetes Plugin from showing the node property, as it passes a wrong class argument.

}
if (!e.hasAttribute('data-checked')) {
FormChecker.delayedCheck("${descriptorPath}/checkName?value="+encodeURIComponent(e.getAttribute("name")),"GET",e.firstChild);
e.setAttribute('data-checked', 'true');
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we add calls to Behavior#applySubtree on the <table>, not doing this attribute check would result in all rows being checked again through unrelated operations on the table. #applySubtree on the row doesn't work (and would still result in 1 unnecessary check each time), so do this instead.

Copy link
Contributor

@Wadeck Wadeck left a comment

Choose a reason for hiding this comment

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

nit: Due to the complexity of the JavaScript I would advice to put it in a separate file, the variables interpretation does not seem mandatory in this case as it could be managed by regular css classes.

The includes is the only "mandatory" change.

}
return true;
};
e = null; <!-- avoid memory leak -->
Copy link
Contributor

Choose a reason for hiding this comment

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

I am really curious about this trick, do you know where it comes from?

From my PoV it seems like premature optimization coming from nowhere ^^ as JS engines have equivalent of Java garbage collector and when a variable is unused, it's cleaned. The e is scoped to the function block and thus is not a global variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea. It's been here from the beginning in 2007, jenkinsci/jenkins@d1ff750#diff-3048bbea3ad809584b44aaf822148017R102. Perhaps related to browser bugs from a decade ago?

return;
}
if (!e.hasAttribute('data-checked')) {
FormChecker.delayedCheck("${descriptorPath}/checkName?value="+encodeURIComponent(e.getAttribute("name")),"GET",e.firstChild);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ if it was delayedCheck('${descriptorPath with single quote instead of double, it would have been XSS vulnerable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any way we can make this safer? encodeURIComponent this part, too?

Copy link
Contributor

Choose a reason for hiding this comment

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

The current version is safe thx to the Jelly escape. Nothing to change, that was just an "informational warning".

EncodeURIComponent will not solve the injection as the malicious code is applied during "jelly compilation" and the encode is called during JavaScript execution. If the malicious code put like ') + alert(1, the encode will be just completely blind :)

@daniel-beck daniel-beck requested a review from Wadeck May 25, 2019 11:24
@daniel-beck daniel-beck merged commit c306c01 into jenkinsci:master Oct 13, 2019
@daniel-beck daniel-beck deleted the JENKINS-46914 branch October 29, 2019 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants