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-70931] Remove Prototype Ajax.Request usages from hudson-behavior.js #7951

Merged
merged 18 commits into from May 11, 2023

Conversation

timja
Copy link
Member

@timja timja commented May 6, 2023

See JENKINS-70931.

Testing done

FormChecker has been tested with the timezone field on the user configuration page.
On page load a doCheck with no attributes is done and works, and then when selecting other timezones it also works

Help fetching has been tested by putting a breakpoint on the code and then clicking help buttons, breakpoint was hit and help areas were loaded.

Lazy map was tested by going to the build time trend and seeing the breakpoint hit on page load and the page looked correct.

Stop button by adding a breakpoint on the code, starting a freestyle build, ensuring the breakpoint was hit and that it behaved as expected.

descriptionForm by editing a freestyle project description, putting a breakpoint ensuring the code was executed behaving as expected

refreshPart was tested by adding a breakpoint and making sure it was hit when executors updated.

validateButton was tested by clicking test connection on the slack plugins global configuration, ensuring breakpoint was hit and it behaved as expected

Proposed changelog entries

  • (skip)

Proposed upgrade guidelines

N/A

Submitter checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples).
    • Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@mention

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@timja timja force-pushed the JENKINS-70931-hudson-behavior branch 2 times, most recently from df81a05 to 8eae594 Compare May 6, 2023 18:50
@timja timja added the skip-changelog Should not be shown in the changelog label May 6, 2023
@timja timja requested review from basil and a team May 6, 2023 19:01
@timja timja marked this pull request as ready for review May 6, 2023 19:01
@timja timja added the needs-security-review Awaiting review by a security team member label May 7, 2023
@timja timja requested a review from a team May 7, 2023 07:38
@basil basil self-assigned this May 7, 2023
@basil basil changed the title JENKINS-70931 Remove Prototype Ajax.Request usages from hudson-behavior.js [JENKINS-70931] Remove Prototype Ajax.Request usages from hudson-behavior.js May 7, 2023
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Fine with me pending the one issue I opened.

war/src/main/webapp/scripts/hudson-behavior.js Outdated Show resolved Hide resolved
@timja timja requested a review from basil May 7, 2023 18:38
basil
basil previously approved these changes May 7, 2023
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Fine but there are still a lot of checkMethod="post" usages in plugins (including proprietary plugins) so maybe we should add a developer changelog entry and/or log a warning instructing the plugin developer to remove the dead code.

@timja timja added developer Changes which impact plugin developers and removed skip-changelog Should not be shown in the changelog labels May 7, 2023
@timja timja force-pushed the JENKINS-70931-hudson-behavior branch from ed2df1c to 3c890bd Compare May 7, 2023 21:31
Copy link
Contributor

@yaroslavafenkin yaroslavafenkin left a comment

Choose a reason for hiding this comment

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

Looks fine to me security wise

@@ -94,89 +77,4 @@ public void onlyAdminCanReachTheDoCheck() throws Exception {
userWc.login(USER);
assertEquals(HttpURLConnection.HTTP_FORBIDDEN, userWc.getPage(request).getWebResponse().getStatusCode());
}

@Test
@Issue("SECURITY-794")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this removed? Not relevant anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was a very hacky test relying on internals of htmlunit which changed when switching to fetch I wasn’t able to replicate it and it didn’t seem like a critical test

@yaroslavafenkin yaroslavafenkin added security-approved @jenkinsci/core-security-review reviewed this PR for security issues and removed needs-security-review Awaiting review by a security team member labels May 8, 2023
@timja
Copy link
Member Author

timja commented May 8, 2023

/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label May 8, 2023
@Wadeck
Copy link
Contributor

Wadeck commented May 8, 2023

log a warning instructing the plugin developer to remove the dead code

Yeah that could be pretty useful.

Also, have you looked for plugins expecting to have checkMethod="get" being supported? It's a breaking change AFAICT.
Quick search seems to provide 0 results.

@timja
Copy link
Member Author

timja commented May 8, 2023

I have checked, it’s in a comment here and like you I found no results

basil added a commit to basil/acceptance-test-harness that referenced this pull request May 8, 2023
basil added a commit to basil/bom that referenced this pull request May 8, 2023
@timja
Copy link
Member Author

timja commented May 9, 2023

Breaks plugins.MatrixAuthPluginTest and plugins.ScriptSecurityPluginTest in ATH.

Fixed

@timja timja requested a review from basil May 9, 2023 21:48
@@ -228,50 +228,73 @@ var FormChecker = {
* @param url
* Remote doXYZ URL that performs the check. Query string should include the field value.
* @param method
* HTTP method. GET or POST. I haven't confirmed specifics, but some browsers seem to cache GET requests.
* Unused, kept to maintain compatibility with the old signature.
Copy link
Member

Choose a reason for hiding this comment

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

matrix-auth and azure-ad call this with "GET". This changes the existing behavior. Not sure there is a valid justification for that.

If there is a valid justification for changing the existing behavior, then this calling convention is pretty ugly. Better to define a new two-argument method and deprecate the three-argument one, logging a warning if anyone is still calling the three-argument version and filing PRs to update consumers.

Copy link
Member Author

Choose a reason for hiding this comment

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

JavaScript doesn't have function overloading.
https://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices

We're stuck with that function with that name.
We could create a new function with a new name and use an object for parameters to make it more flexible in future

Copy link
Member

Choose a reason for hiding this comment

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

Still not sure there is a valid justification for changing the existing behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

core 2.285 changed the default to post, these 2 would have been missed by accident as they will be the only consumers calling it directly.

anyway I've added some compat so they will be able to set GET for now and will file separate PRs to switch them to post if that's okay?

basil
basil previously requested changes May 9, 2023
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

This PR contains two unrelated changes and is too difficult for me to review. Requesting any changes related to the deprecation of checkMethod to be split into a separate PR.

@timja timja added skip-changelog Should not be shown in the changelog and removed developer Changes which impact plugin developers labels May 10, 2023
basil added a commit to basil/acceptance-test-harness that referenced this pull request May 10, 2023
@basil
Copy link
Member

basil commented May 10, 2023

Still failing ATH as far as I can tell.

@basil basil dismissed their stale review May 10, 2023 21:50

changes have been made

@basil
Copy link
Member

basil commented May 10, 2023

Code looks good. Once this gets a passing ATH run (or at least one that is no worse than trunk builds) I will be ready to approve this.

basil added a commit to basil/acceptance-test-harness that referenced this pull request May 11, 2023
@basil
Copy link
Member

basil commented May 11, 2023

ATH passed so this is good to go from my perspective.

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Thanks for your hard work cleaning up this patch and getting ATH to pass!


This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process. Thanks!

@basil basil added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label May 11, 2023
@basil basil merged commit df1ef51 into jenkinsci:master May 11, 2023
16 checks passed
var idx = url.indexOf("?");
params.parameters = url.substring(idx + 1);
url = url.substring(0, idx);
}
new Ajax.Request(url, params);

const parsedUrl = method === "get" ? `${url}?${params.parameters}` : url;
Copy link
Member

Choose a reason for hiding this comment

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

This is a breaking change when the request method is GET, as params.parameters is undefined.

matrix-auth:

Screenshot 2023-05-12 at 10 52 20

(The ] is from the internal format of form validation requested in the plugin. The original url looks like /jenkins/manage/descriptorByName/hudson.security.ProjectMatrixAuthorizationStrategy/checkName?value=%5BUSER%3AtheUsername%5D)

Copy link
Member Author

Choose a reason for hiding this comment

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

👉 #7986

@@ -242,36 +242,65 @@ var FormChecker = {
},

sendRequest: function (url, params) {

Choose a reason for hiding this comment

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

I realize I'm late to the party, but are we cool with breaking this function? It's used in plugins and the response parameter in onComplete having no responseText is a bit of a surprise to all the scripts.

Copy link
Member

Choose a reason for hiding this comment

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

Could you clarify what's being broken? What scripts?

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback security-approved @jenkinsci/core-security-review reviewed this PR for security issues skip-changelog Should not be shown in the changelog
Projects
None yet
7 participants