Skip to content

Issue CodeScan url redirect #560

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
107 changes: 74 additions & 33 deletions dev-workflow-ui/webContent/view/frame.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:pe="http://primefaces.org/ui/extensions">
<h:body>
<f:metadata>
<f:viewParam name="originalUrl" value="#{frameIvyDevWfBean.originalUrl}"/>
<f:viewParam name="originalUrl" value="#{frameIvyDevWfBean.originalUrl}" />
</f:metadata>
<ui:composition template="../includes/template/template.xhtml">
<ui:define name="content">
Expand All @@ -13,26 +13,31 @@
<div class="card-header pb-0">
<div class="card-title flex align-items-center">
<i class="pr-3 si si-task-list-edit"></i>
<h6 class="m-0"><h:outputText id="frameTaskName" value="#{frameIvyDevWfBean.taskName}" /></h6>
<h6 class="m-0">
<h:outputText id="frameTaskName" value="#{frameIvyDevWfBean.taskName}" />
</h6>
</div>
<p:linkButton id="openStartFullscreenBtn" href="#{frameIvyDevWfBean.taskUrl}" icon="si si-expand-6"
styleClass="ml-auto ui-button-secondary rounded-button"/>
<p:tooltip for="openStartFullscreenBtn" value="Open current process start on a fullscreen page" position="left"/>
styleClass="ml-auto ui-button-secondary rounded-button" />
<p:tooltip for="openStartFullscreenBtn" value="Open current process start on a fullscreen page"
position="left" />
<p:commandButton value="Sidesteps" styleClass="ml-1" id="sidestepsBtn"
rendered="#{frameIvyDevWfBean.renderSidestepBtn()}" icon="si si-arrow-down-1" />
<p:menu id="sidestepMenu" overlay="true" trigger="sidestepsBtn" my="right top" at="right bottom"
model="#{frameIvyDevWfBean.sidestepsMenuModel}" styleClass="menu-no-icons" />
</div>
<p:remoteCommand name="useTaskInIFrame" actionListener="#{frameIvyDevWfBean.useTaskInIFrame()}" update="@form" />
<p:remoteCommand name="useTaskInIFrame" actionListener="#{frameIvyDevWfBean.useTaskInIFrame()}"
update="@form" />
</h:form>
<hr/>
<iframe id="iFrame" src="#{frameIvyDevWfBean.taskUrl}" style="height: calc(100vh - 205px); width: 100%; border: 0; visibility: hidden;"></iframe>
<hr />
<iframe id="iFrame" src="#{frameIvyDevWfBean.taskUrl}"
style="height: calc(100vh - 205px); width: 100%; border: 0; visibility: hidden;"></iframe>
</div>
<script>
function iframeURLChange(iframe, callback) {
var lastDispatched = null;

var dispatchChange = function() {
var dispatchChange = function () {
useTaskInIFrame([{
name: 'url',
value: iframe.contentWindow.location.pathname
Expand All @@ -47,14 +52,14 @@
}
};

var updateHistory = function(newHref) {
var updateHistory = function (newHref) {
var newHrefUrl = new URL(newHref);
var historyUrl = new URL(window.location);
historyUrl.searchParams.set('taskUrl', newHrefUrl.pathname + newHrefUrl.search);
history.replaceState({}, "", historyUrl);
}

var unloadHandler = function() {
var unloadHandler = function () {
// Timeout needed because the URL changes immediately after
// the `unload` event is dispatched.
setTimeout(dispatchChange, 0);
Expand All @@ -68,15 +73,15 @@
iframe.contentWindow.addEventListener("unload", unloadHandler);
}

iframe.addEventListener("load", function() {
iframe.addEventListener("load", function () {
try {
// Try to access loaded iframe content
iframe.contentWindow.content;
attachUnload();
// Just in case the change wasn't dispatched during the unload event...
dispatchChange();
iframe.style.visibility = 'visible';
} catch(e) {
} catch (e) {
// Open iframe content in current window if it could not be loaded
window.location = iframe.src;
}
Expand All @@ -85,35 +90,71 @@
attachUnload();
}

const TASK = 'task.xhtml';
const TASKS = 'tasks.xhtml';
const CASE = 'case.xhtml';
const CASES = 'cases.xhtml';
const HOME = 'home.xhtml';
const STARTS = 'starts.xhtml';
const LOGIN = 'login.xhtml';
const LOGINTABLE = 'loginTable.xhtml';

const authorizedUrls = new Map([
['/home.xhtml', HOME],
['/tasks.xhtml', TASKS],
['/starts.xhtml', STARTS],
['/login.xhtml', LOGIN],
['/loginTable.xhtml', LOGINTABLE],
['/end.xhtml', HOME],
['DefaultApplicationHomePage.ivp', HOME],
['DefaultTaskListPage.ivp', TASKS],
['DefaultProcessStartListPage.ivp', STARTS],
['DefaultLoginPage.ivp', LOGIN],
['DefaultEndPage.ivp', HOME]
]);

function checkAndReturnUrl(newURL, originPage) {
if (newURL.includes('task.xhtml')){
return newURL.substring(newURL.indexOf('task.xhtml'));
}
if (newURL.includes('?endedTaskId=')) {
return originPage;
}
if (newURL.endsWith('/faces/home.xhtml') || newURL.includes('DefaultApplicationHomePage.ivp') || newURL.endsWith('/app/home.xhtml')) {
return 'home.xhtml';
}
if (newURL.endsWith('/faces/tasks.xhtml') || newURL.includes('DefaultTaskListPage.ivp') || newURL.endsWith('/app/tasks.xhtml')) {
return 'tasks.xhtml';
}
if (newURL.endsWith('/faces/starts.xhtml') || newURL.includes('DefaultProcessStartListPage.ivp') || newURL.endsWith('/app/starts.xhtml')) {
return 'starts.xhtml';
alert("start newURL: " + newURL + " | originPage: " + originPage);
if (newURL.includes(TASK)) {
alert("return substringTask " + newURL.substring(newURL.indexOf(TASK)));
return newURL.substring(newURL.indexOf(TASK));
}
if (newURL.endsWith('/faces/login.xhtml') || newURL.includes('DefaultLoginPage.ivp') || newURL.endsWith('/app/login.xhtml')) {
return 'login.xhtml';

//xhtml isnt working with and?
if (newURL.includes('?endedTaskId=')){
if (originPage.includes(TASK + "?id")) {
var id = originPage.split("id=");
if (id.length == 2) {
alert("return task: "+TASK + "?id=" + id[1]);
return TASK+ "?id=" + id[1];
}
alert("return tasks");
return TASKS;
}
}
if (newURL.endsWith('/faces/loginTable.xhtml')) {
return 'loginTable.xhtml';
if (newURL.includes('case.xhtml?id')) {
var id = originPage.split("id=")[1];
if (id != null) {
alert("return case");
return CASE + "?id=" + id;
}
alert("return cases");
return CASES;
}
if (newURL.endsWith('/faces/end.xhtml') || newURL.includes('DefaultEndPage.ivp') || newURL.endsWith('/app/end.xhtml')) {
return originPage;

var entry = [...authorizedUrls.entries()].find(([key, value]) =>
newURL.includes(key)
);
if (entry != null) {
alert("return, redirect to " + entry[1]);
return entry[1];
}

alert("undefined");
return undefined;
}

iframeURLChange(document.getElementById("iFrame"), function(newURL, iframe) {
iframeURLChange(document.getElementById("iFrame"), function (newURL, iframe) {
var originPage = new URLSearchParams(window.location.search).get('originalUrl');
if (iframe.contentWindow.location.pathname.match("/default/redirect.xhtml")) {
var redirectedPage = new URLSearchParams(iframe.contentWindow.location.search).get("redirectPage");
Expand Down