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-74026][JENKINS-74027] Improve CSP compatibility #380

Merged
merged 3 commits into from
Nov 23, 2024
Merged
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
@@ -0,0 +1,20 @@
if (window.makeStaplerProxy) {
window.__old__makeStaplerProxy = window.makeStaplerProxy;
window.makeStaplerProxy = UnoChoice.makeStaplerProxy2;
}

window.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".cascade-choice-parameter-data-holder").forEach((dataHolder) => {
const { name, paramName, randomName, proxyName } = dataHolder.dataset;
const referencedParameters = dataHolder.dataset.referencedParameters.split(",").map((val) => val.trim());
const filterable = dataHolder.dataset.filterable === "true";
const filterLength = parseInt(dataHolder.dataset.filterLength);

UnoChoice.renderCascadeChoiceParameter(`#${paramName}`, filterable, name, randomName, filterLength, paramName, referencedParameters, window[proxyName]);
});

if (window.makeStaplerProxy && window.__old__makeStaplerProxy) {
window.makeStaplerProxy = window.__old__makeStaplerProxy;
delete window["__old__makeStaplerProxy"];
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
${it.parameters.clear()}
<st:include page="/org/biouno/unochoice/common/choiceParameterCommon.jelly"/>
<st:bind value="${it}" var="cascadeChoiceParameter"/>
<script type="text/javascript">
// source, references table
var referencedParameters = Array();
<j:forEach var="value" items="${it.getReferencedParametersAsArray()}">
// add the element we want to monitor
referencedParameters.push("${value}");
</j:forEach>

if (window.makeStaplerProxy) {
window.__old__makeStaplerProxy = window.makeStaplerProxy;
window.makeStaplerProxy = UnoChoice.makeStaplerProxy2;
}
var cascadeChoiceParameter = <st:bind value="${it}"/>; // Create Jenkins proxy
if (window.makeStaplerProxy) {
window.makeStaplerProxy = window.__old__makeStaplerProxy;
}
UnoChoice.renderCascadeChoiceParameter('#${h.escape(paramName)}', ${it.filterable}, '${h.escape(it.getName())}', '${h.escape(it.getRandomName())}', ${it.getFilterLength()}, '${h.escape(paramName)}', referencedParameters, cascadeChoiceParameter);

</script>
<j:set var="proxyName" value="cascadeChoiceParameter_${h.generateId()}"/>
<span class="cascade-choice-parameter-data-holder"
data-proxy-name="${proxyName}"
data-referenced-parameters="${it.getReferencedParameters()}"
data-param-name="${h.escape(paramName)}"
data-name="${h.escape(it.getName())}"
data-filterable="${it.filterable}"
data-random-name="${h.escape(it.getRandomName())}"
data-filter-length="${it.getFilterLength()}"/>
<st:adjunct includes="org.biouno.unochoice.CascadeChoiceParameter.cascade-choice-parameter"/>
<st:bind value="${it}" var="${proxyName}"/>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
if (window.makeStaplerProxy) {
window.__old__makeStaplerProxy = window.makeStaplerProxy;
window.makeStaplerProxy = UnoChoice.makeStaplerProxy2;
}

window.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".dynamic-reference-parameter-data-holder").forEach((dataHolder) => {
const { name, paramName, proxyName } = dataHolder.dataset;
const referencedParameters = dataHolder.dataset.referencedParameters.split(",").map((val) => val.trim());

UnoChoice.renderDynamicRenderParameter(`#${paramName}`, name, paramName, referencedParameters, window[proxyName]);

// update spinner id
var rootElmt = document.querySelector(`#${paramName}`);
if (rootElmt) {
var divElmt = rootElmt.querySelector("div");
if (divElmt) {
var spinnerId = divElmt.id.split("_").pop();
document.querySelector(`#${paramName}-spinner`).setAttribute("id", spinnerId + "-spinner");
}
}
});

if (window.makeStaplerProxy && window.__old__makeStaplerProxy) {
window.makeStaplerProxy = window.__old__makeStaplerProxy;
delete window["__old__makeStaplerProxy"];
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,12 @@
</j:choose>
</div>
</f:entry>
<st:bind value="${it}" var="dynamicReferenceParameter"/>
<script type="text/javascript">
// source, references table
var referencedParameters = Array();
<j:forEach var="value" items="${it.getReferencedParametersAsArray()}">
// add the element we want to monitor
referencedParameters.push("${value}");
</j:forEach>

if (window.makeStaplerProxy) {
window.__old__makeStaplerProxy = window.makeStaplerProxy;
window.makeStaplerProxy = UnoChoice.makeStaplerProxy2;
}
var dynamicReferenceParameter = <st:bind value="${it}"/>; // Create Jenkins proxy
if (window.makeStaplerProxy) {
window.makeStaplerProxy = window.__old__makeStaplerProxy;
}
UnoChoice.renderDynamicRenderParameter('#${paramName}', '${h.escape(it.getName())}', '${h.escape(paramName)}', referencedParameters, dynamicReferenceParameter);

// update spinner id
var rootElmt = document.querySelector('#${paramName}');
if (rootElmt) {
var divElmt = rootElmt.querySelector('div');
if (divElmt) {
var spinnerId = divElmt.id.split('_').pop();
document.querySelector('#${paramName}-spinner').setAttribute('id', spinnerId + '-spinner');
}
}
</script>
<j:set var="proxyName" value="dynamicReferenceParameter_${h.generateId()}"/>
<span class="dynamic-reference-parameter-data-holder"
data-proxy-name="${proxyName}"
data-referenced-parameters="${it.getReferencedParameters()}"
data-param-name="${paramName}"
data-name="${h.escape(it.getName())}"/>
<st:adjunct includes="org.biouno.unochoice.DynamicReferenceParameter.dynamic-reference-parameter"/>
<st:bind value="${it}" var="${proxyName}"/>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void testReferenceParameterXss() throws IOException, SAXException {
"random-name",
script,
DynamicReferenceParameter.ELEMENT_TYPE_FORMATTED_HTML,
null,
"",
Copy link
Author

Choose a reason for hiding this comment

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

Never a null when saved via UI.

false);
project.addProperty(new ParametersDefinitionProperty(parameter));
project.save();
Expand Down