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

CSP compatibility improvements #533

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

CSP compatibility improvements #533

wants to merge 4 commits into from

Conversation

zbynek
Copy link
Contributor

@zbynek zbynek commented May 26, 2024

Somewhat related to https://issues.jenkins.io/browse/JENKINS-73166 which showed that geval is used by this plugin.

This PR reduces usages of inline JS to improve CSP compatibility.

Testing done

Manually checked that the affected functionality is still OK:

  • certificate can be uploaded, validated and updated
  • new domain creation: submit button deactivates for empty name, auto-focus works
  • same for domain configuration
  • help for "include user credentials" working (in a job parameter)

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@zbynek zbynek requested a review from a team as a code owner May 26, 2024 20:14
@zbynek zbynek marked this pull request as draft May 26, 2024 20:14
@zbynek zbynek marked this pull request as ready for review May 30, 2024 21:05
@@ -49,10 +49,6 @@
</f:bottomButtonBar>
</f:form>
</j:scope>
<script>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sticky footer no longer needs realigning explicitly from JS.

@@ -72,10 +72,6 @@
<f:submit value="${%Create}"/>
</f:bottomButtonBar>
</f:form>
<script>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sticky footer no longer needs realigning explicitly from JS.

@@ -44,7 +44,7 @@
<j:otherwise>
<f:form action="configSubmit" method="POST" name="config">
<f:entry title="${%Name}" help="/plugin/credentials/help/domain/name.html">
<f:textbox field="name" id="name" onchange="updateSave(this.form)" onkeyup="updateSave(this.form)"/>
<f:textbox field="name" clazz="required-for-submit"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to formBehaviour.js

@@ -54,28 +54,14 @@
items="${instance.specifications}"/>
</f:entry>
<f:bottomButtonBar>
<input type="submit" name="Submit" value="${%Save}" id="save" class="submit-button primary" />
<button formnovalidate="formNoValidate" id="save" name="Submit" class="jenkins-button jenkins-button--primary">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to standard button to avoid the need for makeButton JS function.

}

// workaround for JENKINS-19124
// without this script, the password changes will be not trigger the check on the uploadedKeystore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code changed significantly but the reasoning is still the same: I couldn't find a way how to make password textfield trigger validation of the cert field, since there are multiple fields named password in the form and they are on higher level than the cert upload field.

Copy link
Member

Choose a reason for hiding this comment

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

@RealativePath(..) is the way. There is a bug https://issues.jenkins.io/browse/JENKINS-65616 that causes this to work for some validation triggers, but not others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The relative path can't be just password because the field is on a higher level. But the relative path ../password matches the wrong password.

@zbynek zbynek force-pushed the csp branch 3 times, most recently from 8a4ee3f to da5c849 Compare May 30, 2024 22:08
@@ -0,0 +1,57 @@
// multiple objects named "password" in the form =>
// extend findNearBy to allow selecting by id
if (!findNearBy.patched) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think allowing IDs or CSS selectors in checkDependsOn instead of just names would help with ambiguities. Should be probably done in core, but for now can be patched in plugins like this.

@daniel-beck do you have a better idea?

Copy link
Member

Choose a reason for hiding this comment

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

@jenkinsci/core-security-review Any objection to this technique?

mawinter69 added a commit to mawinter69/jenkins that referenced this pull request Jul 20, 2024
The YUI library is old and no longer maintained.

Add a user experimental flag to disable YUI. It's disabled by default.
When enabling all the YUI related js libraries and css classes are not
loaded.

Following PR are required to get Jenkins to not show any errors

eventually jenkinsci#7569

Some plugins that use YUI (not complete):
credentials
ldap
global-build-stats
build-monitor
categorized-view

Plugins that make use of makeButton (not complete)
credentials (fixed with jenkinsci/credentials-plugin#533)
openid

acceptance-test-harness
mawinter69 added a commit to mawinter69/jenkins that referenced this pull request Jul 20, 2024
The YUI library is old and no longer maintained.

Add a user experimental flag to disable YUI. It's disabled by default.
When enabling all the YUI related js libraries and css classes are not
loaded.

Following PR are required to get Jenkins to not show any errors

eventually jenkinsci#7569

Some plugins that use YUI (not complete):
credentials
ldap
global-build-stats
build-monitor
categorized-view

Plugins that make use of makeButton (not complete)
credentials (fixed with jenkinsci/credentials-plugin#533)
openid

acceptance-test-harness
NotMyFault pushed a commit to jenkinsci/jenkins that referenced this pull request Jul 22, 2024
* experimental flag to run Jenkins without YUI

The YUI library is old and no longer maintained.

Add a user experimental flag to disable YUI. It's disabled by default.
When enabling all the YUI related js libraries and css classes are not
loaded.

Following PR are required to get Jenkins to not show any errors

eventually #7569

Some plugins that use YUI (not complete):
credentials
ldap
global-build-stats
build-monitor
categorized-view

Plugins that make use of makeButton (not complete)
credentials (fixed with jenkinsci/credentials-plugin#533)
openid

acceptance-test-harness

* fix typo

Co-authored-by: Jan Faracik <43062514+janfaracik@users.noreply.github.com>

* add license and restrict class

---------

Co-authored-by: Jan Faracik <43062514+janfaracik@users.noreply.github.com>
@zbynek
Copy link
Contributor Author

zbynek commented Aug 2, 2024

@mawinter69 note that this is only partial fix for removing YUI from this plugin, there will still one YUI button and one popup menu left.

@mawinter69
Copy link

I know #551 will do the rest

@basil basil requested a review from a team August 22, 2024 20:22
@timja timja requested a review from jtnord September 26, 2024 21:24
}
}

// workaround for JENKINS-65616
Copy link
Member

@jtnord jtnord Sep 27, 2024

Choose a reason for hiding this comment

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

JENKINS-65616 aka Form validation not working with different "level/layer" of fields

Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

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

seems reasonable pending review from core-security-review requested by Basil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants