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

Make plugin CSP compliant #78

Merged
merged 4 commits into from
Jan 10, 2025
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>gradle</artifactId>
<version>2.9</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2.9 doesn't exist in https://repo.jenkins-ci.org/artifactory/releases/org/jenkins-ci/plugins/gradle/, so project wasn't building for me locally.

<version>2.12.0.1</version>
</dependency>

<!-- for Credentials support -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,7 @@
<div>
<img id="nvsGraph" src="${action.urlName}/graph" />
</div>
<script defer="true">
var stamp = new Date().getTime();
function checkGraphUpdate() {
fetch("${action.urlName}/checkUpdates", {
method: 'POST',
headers: crumb.wrap({
'Content-Type': 'application/x-www-form-urlencoded'
}),
body: new URLSearchParams({
stamp: stamp,
})
}).then(function(rsp) {
if (rsp.ok) {
var update = rsp.headers.get('go');
if(update == "go") {
stamp = new Date().getTime();
var image = document.getElementById('nvsGraph');
if(image.complete) {
var new_image = new Image();
new_image.id = "nvsGraph";
new_image.src = image.src + "?v=" + stamp;
// insert new image and remove old
image.parentNode.insertBefore(new_image,image);
image.parentNode.removeChild(image);
}
}
// next update in 10 sec
window.setTimeout(checkGraphUpdate, 10000);
}
});
}
window.setTimeout(checkGraphUpdate, 15000);
</script>
<st:adjunct includes="com.fortify.plugin.jenkins.ChartAction.graph"/>
<span class="fortify-graph-data-holder" data-url-name="${action.urlName}"/>
</div>
</j:jelly>
35 changes: 35 additions & 0 deletions src/main/resources/com/fortify/plugin/jenkins/ChartAction/graph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
document.addEventListener("DOMContentLoaded", () => {
const { urlName } = document.querySelector(".fortify-graph-data-holder").dataset;

var stamp = new Date().getTime();
function checkGraphUpdate() {
fetch(`${urlName}/checkUpdates`, {
method: 'POST',
headers: crumb.wrap({
'Content-Type': 'application/x-www-form-urlencoded'
}),
body: new URLSearchParams({
stamp: stamp,
})
}).then(function(rsp) {
if (rsp.ok) {
var update = rsp.headers.get('go');
if(update == "go") {
stamp = new Date().getTime();
var image = document.getElementById('nvsGraph');
if(image.complete) {
var new_image = new Image();
new_image.id = "nvsGraph";
new_image.src = image.src + "?v=" + stamp;
// insert new image and remove old
image.parentNode.insertBefore(new_image,image);
image.parentNode.removeChild(image);
}
}
// next update in 10 sec
window.setTimeout(checkGraphUpdate, 10000);
}
});
}
window.setTimeout(checkGraphUpdate, 15000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
<f:editableComboBox id="projectName1" field="appName" clazz="setting-input project-name read-only" items="${descriptor.appNameItems}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton1" onclick="refreshProjectNames('${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton1" class="fortify-refresh-button" data-callback="refreshProjectNames"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects"/>
</div>
<div style="display:none;" id="refreshSpinner" >
<img src="${imagesURL}/spinner.gif" /> ${progress}
Expand All @@ -102,7 +103,8 @@
<f:editableComboBox id="projectVersion1" field="appVersion" clazz="setting-input project-version read-only" items="${descriptor.appVersionItems(appName)}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton1" onclick="refreshProjectVersions('${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton1" class="fortify-refresh-button" data-callback="refreshProjectVersions"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions" />
</div>
<div style="display:none;" id="refreshSpinnerVer" >
<img src="${imagesURL}/spinner.gif" />
Expand Down Expand Up @@ -193,7 +195,8 @@
<f:editableComboBox id="projectName2" field="appName" clazz="setting-input project-name read-only" items="${descriptor.appNameItems}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton2" onclick="refreshProjectNames('${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton2" class="fortify-refresh-button" data-callback="refreshProjectNames"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects" />
</div>
<div style="display:none;" id="refreshSpinner" >
<img src="${imagesURL}/spinner.gif" /> ${progress}
Expand All @@ -205,7 +208,8 @@
<f:editableComboBox id="projectVersion2" field="appVersion" clazz="setting-input project-version read-only" items="${descriptor.appVersionItems(appName)}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton2" onclick="refreshProjectVersions('${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton2" class="fortify-refresh-button" data-callback="refreshProjectVersions"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions" />
</div>
<div style="clear:both" />
</f:entry>
Expand Down Expand Up @@ -300,7 +304,8 @@
<f:editableComboBox id="projectName3" field="appName" clazz="setting-input project-name" items="${descriptor.appNameItems}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton3" onclick="refreshProjectNames('${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton3" class="fortify-refresh-button" data-callback="refreshProjectNames"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects" />
</div>
<div style="display:none;" id="refreshSpinner" >
<img src="${imagesURL}/spinner.gif" /> ${progress}
Expand All @@ -312,7 +317,8 @@
<f:editableComboBox id="projectVersion3" field="appVersion" clazz="setting-input project-version" items="${descriptor.appVersionItems(appName)}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton3" onclick="refreshProjectVersions('${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton3" class="fortify-refresh-button" data-callback="refreshProjectVersions"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions" />
</div>
<div style="clear:both" />
</f:entry>
Expand Down Expand Up @@ -349,7 +355,8 @@
<f:editableComboBox id="projectName4" field="appName" clazz="setting-input project-name" items="${descriptor.appNameItems}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton4" onclick="refreshProjectNames('${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton4" class="fortify-refresh-button" data-callback="refreshProjectNames"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects" />
</div>
<div style="display:none;" >
<img src="${imagesURL}/spinner.gif" /> ${progress}
Expand All @@ -361,7 +368,8 @@
<f:editableComboBox id="projectVersion4" field="appVersion" clazz="setting-input project-version" items="${descriptor.appVersionItems(appName)}" />
</div>
<div style="float:left;">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton4" onclick="refreshProjectVersions('${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton4" class="fortify-refresh-button" data-callback="refreshProjectVersions"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions" />
</div>
<div style="clear:both" />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<f:editableComboBox id="projectTemplate" name="projectTemplate" field="projectTemplate" clazz="setting-input" items="${descriptor.projectTemplateItems}" checkMethod="post"/>
</div>
<div style="float:left">
<input value="▼" type="button" id="refreshButton" onclick="refreshTemplateList('${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjectTemplates','url,sscTokenCredentialsId,isProxy')" />
<input value="▼" type="button" id="refreshButton" data-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjectTemplates" data-param-list="url,sscTokenCredentialsId,isProxy"/>
</div>
<div style="display:none;" id="refreshSpinner" >
<img src="${imagesURL}/spinner.gif" /> ${progress}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
<l:header>
<link rel="stylesheet" type="text/css" href="${rootURL}/plugin/fortify/issueStyles.css"/>
<script src="${rootURL}/plugin/fortify/refresh-issues.js"></script>
<script type="text/javascript" defer="true">
var stamp = new Date().getTime();
var contextUrl = '${h.getActionUrl(it.project.url,it)}';
</script>
<span class="table-action-data-holder" data-context-url="${h.getActionUrl(it.project.url,it)}" data-images-url="${imagesURL}"/>
</l:header>

<st:include page="sidepanel.jelly" it="${it.project}"/>
Expand All @@ -48,9 +45,6 @@
<j:otherwise>
You have to build your project in order to access Fortify Assessment results
</j:otherwise>
<script type="text/javascript" defer="true">
loadIssueTable('${imagesURL}/spinner.gif');
</script>
</j:choose>
</l:main-panel>
</l:layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton"
onclick="refreshProjectNames('${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects', this)"/>
class="fortify-refresh-button" data-callback="refreshProjectNames"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects"/>
</div>
<div style="display:none;" id="refreshSpinner">
<img src="${imagesURL}/spinner.gif"/>
Expand All @@ -90,7 +91,8 @@
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton"
onclick="refreshProjectVersions('${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions', this)"/>
class="fortify-refresh-button" data-callback="refreshProjectVersions"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions"/>
</div>
<div style="clear:both" />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton"
onclick="refreshProjectNames('${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects', this)"/>
class="fortify-refresh-button" data-callback="refreshProjectNames"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshProjects"/>
</div>
<div style="display:none;" id="refreshSpinner">
<img src="${imagesURL}/spinner.gif"/>
Expand All @@ -85,7 +86,8 @@
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton"
onclick="refreshProjectVersions('${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions', this)"/>
class="fortify-refresh-button" data-callback="refreshProjectVersions"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions"/>
</div>
<div style="clear:both" />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<f:editableComboBox id="projectName" name="appName" field="appName" clazz="setting-input project-name" items="${descriptor.applicationNameItems}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton" onclick="refreshProjectNames('${rootURL}/descriptor/${descriptor.clazz.name}/refreshApplications', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjButton" class="fortify-refresh-button" data-callback="refreshProjectNames"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshApplications" />
</div>
<div style="display:none;" id="refreshSpinner" >
<img src="${imagesURL}/spinner.gif" /> ${progress}
Expand All @@ -36,7 +37,8 @@
<f:editableComboBox id="projectVersion" name="appVersion" field="appVersion" clazz="setting-input project-version" items="${descriptor.applicationVersionItems(appName)}" />
</div>
<div style="float:left">
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton" onclick="refreshProjectVersions('${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions', this)" />
<input value="&#x1F50E;&#xFE0E;" type="button" id="refreshPrjVerButton" class="fortify-refresh-button" data-callback="refreshProjectVersions"
data-refresh-url="${rootURL}/descriptor/${descriptor.clazz.name}/refreshVersions" />
</div>
<div style="clear:both" />
</f:entry>
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/refresh-issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,10 @@
}
window.setTimeout(loadIssues, 0);
}

document.addEventListener("DOMContentLoaded", () => {
window.stamp = new Date().getTime();
var { contextUrl, imagesUrl } = document.querySelector(".table-action-data-holder").dataset;
window.contextUrl = contextUrl;
loadIssueTable(`${imagesUrl}/spinner.gif`);
});
18 changes: 17 additions & 1 deletion src/main/webapp/refresh-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,20 @@ function disableCtrlURLInput() {
}
}

window.addEventListener("load", disableCtrlURLInput);
window.addEventListener("DOMContentLoaded", () => {
disableCtrlURLInput();

document.querySelector("#refreshButton").addEventListener("click", (event) => {
const { url, paramList } = event.target.dataset;
refreshTemplateList(url, paramList);
});
});

Behaviour.specify(".fortify-refresh-button", "fortify-refresh-button-behaviour", 0, (button) => {
button.addEventListener("click", (event) => {
const target = event.target;
const { refreshUrl, callback } = target.dataset;

window[callback](refreshUrl, target);
});
});