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

updated for CSP compatibility: eval call in datasource-{min,debug}.js #9090

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pyther-hub
Copy link

See JENKINS-71519.
The code was modified where eval was utilized because it's discouraged to utilize eval for interpreting a string as JavaScript code.

Testing done

Proposed changelog entries

  • JENKINS-XXXXX, human-readable text

Proposed upgrade guidelines

N/A

Submitter checklist

Desired reviewers

@mention

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

Maintainer checklist

Copy link

welcome bot commented Mar 27, 2024

Yay, your first pull request towards Jenkins core was created successfully! Thank you so much!

A contributor will provide feedback soon. Meanwhile, you can join the chats and community forums to connect with other Jenkins users, developers, and maintainers.

@daniel-beck
Copy link
Member

@pyther-hub Thanks for your PR. Are you aware of current uses of this code and if so, could you provide links to them or instructions how to test them? eval is more permissive than JSON#parse, so this may break existing uses.

@pyther-hub
Copy link
Author

I attempted to locate some tests, but unfortunately, I was unable to find any as in the issue it was clearly mentioned of not using eval so made the changes according and even in the documentation I personally do not believe that there would be any issue with it, I would definitely try to find some test for this

@mawinter69
Copy link
Contributor

Is the code with the eval ever reached with modern browser?
I think we will always go into this if block else if(window.JSON && JSON.parse) { (lines 1064 resp. 1112)

@pyther-hub
Copy link
Author

@mawinter69 could you explain it a more

@mawinter69
Copy link
Contributor

See https://www.jenkins.io/doc/book/platform-information/support-policy-web-browsers/ for which browsers Jenkins supports.
Now according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON all browsers that Jenkins supports have a global JSON object and the parse method.
So for them if(window.JSON && JSON.parse) will evaluate to true and we will never reach the eval code.

@pyther-hub
Copy link
Author

Yes, I understand and agree with you. However, I believe it's important to address this for future considerations. If there are any changes, we should consider removing the 'eval'.

@zbynek
Copy link
Contributor

zbynek commented Jul 11, 2024

@pyther-hub your code now is basically

if (window.JSON && JSON.parse) {
JSON.parse(stuff):
} else {
JSON.parse(stuff);
}

If we want to merge this PR I'd suggest to simplify this to

JSON.parse(stuff)

That being said, I think we're pretty close to removing all usages of YUI framework from core and then we don't have to care about the files changed in this PR.

@mawinter69
Copy link
Contributor

I started an epic to remote YUI from Jenkins: https://issues.jenkins.io/browse/JENKINS-73539
The last usage of YUI in core is then addressed by #9511

Besides core, I found 38 plugins that make direct usage of YUI, I opened corresponding issues for them. Some plugins are abandoned and haven't been released since years, but I'm confident we can get almost all plugins with more than 1000 installations to remove YUI. For several there are already PRs open that will remove YUI or I created PRs.

The complete list of plugins is here:
https://docs.google.com/spreadsheets/d/1UjvtFmNmEdjMN5DUoFxJfBryA8q-E5_HwOzVKbVG9b0/edit?usp=sharing

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