Skip to content
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
Expand Up @@ -242,7 +242,8 @@ export class WorkflowBuilder {
/** Zoom to a specific level, centred on the canvas midpoint. */
setZoom(newZoom) {
const rect = this.canvas.getBoundingClientRect();
const cx = rect.width / 2, cy = rect.height / 2;
const cx = this.canvas.scrollLeft + (rect.width / 2);
const cy = this.canvas.scrollTop + (rect.height / 2);
const oldZoom = this.zoom;
this.zoom = Math.min(this.maxZoom, Math.max(this.minZoom, newZoom));
const scale = this.zoom / oldZoom;
Expand Down Expand Up @@ -1646,8 +1647,10 @@ export class WorkflowBuilder {
`;

fields.forEach(field => {
const escapedPrefillSourceText = this.escapeHtml(field.prefill_source);
const escapedPrefillSourceTitle = this.escapeHtmlAttribute(field.prefill_source);
const prefillBadge = field.prefill_source ?
`<span class="badge bg-info ms-2" title="Auto-filled from ${this.escapeHtml(field.prefill_source)}"><i class="bi bi-magic"></i> ${this.escapeHtml(field.prefill_source)}</span>` : '';
`<span class="badge bg-info ms-2" title="Auto-filled from ${escapedPrefillSourceTitle}"><i class="bi bi-magic"></i> ${escapedPrefillSourceText}</span>` : '';
const requiredBadge = field.required ?
`<span class="badge bg-warning ms-1">Required</span>` : '';

Expand Down Expand Up @@ -2174,9 +2177,10 @@ export class WorkflowBuilder {
if (!node) return;

const groups = this.getNormalizedStageApprovalGroups(node.data.approval_groups || []);
const currentIndex = groups.findIndex(group => (
group.id === groupId && (groupRole === null || group.role === groupRole)
));
const currentIndex = groups.findIndex(group => {
const normalizedRole = group.role || 'approval';
return group.id === groupId && (groupRole === null || normalizedRole === groupRole);
});
const targetIndex = currentIndex + direction;
if (currentIndex < 0 || targetIndex < 0 || targetIndex >= groups.length) {
return;
Expand Down Expand Up @@ -2794,7 +2798,8 @@ export class WorkflowBuilder {
}

const badgeHtml = badges ? `${badges}<br>` : '';
return `${badgeHtml}${fieldCount} field${fieldCount !== 1 ? 's' : ''} • <a href="${node.data.form_builder_url || '#'}" target="_blank" class="text-primary form-edit-link"><i class="bi bi-pencil-square"></i> Edit Form</a>`;
const safeFormBuilderUrl = this.escapeHtmlAttribute(this.sanitizeFormBuilderUrl(node.data.form_builder_url || '#'));
return `${badgeHtml}${fieldCount} field${fieldCount !== 1 ? 's' : ''} • <a href="${safeFormBuilderUrl}" target="_blank" rel="noopener noreferrer" class="text-primary form-edit-link"><i class="bi bi-pencil-square"></i> Edit Form</a>`;
case 'workflow_settings':
const parts_ws = [];
if (node.data.name_label) parts_ws.push(this.escapeHtml(node.data.name_label));
Expand Down
39 changes: 39 additions & 0 deletions tests_js/workflow-builder/review246.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ describe('workflow builder review fixes', () => {
expect(instance.panY).toBeCloseTo(-12);
});

it('keeps the visible canvas center fixed when zooming with the toolbar', () => {
const instance = createInstance();
instance.canvas = document.createElement('div');
instance.canvas.scrollLeft = 40;
instance.canvas.scrollTop = 20;
instance.canvas.getBoundingClientRect = () => ({ width: 200, height: 100 });
instance.zoom = 1;
instance.minZoom = 0.25;
instance.maxZoom = 2;
instance.panX = 0;
instance.panY = 0;
instance.applyTransform = vi.fn();
instance.updateZoomIndicator = vi.fn();

instance.setZoom(1.5);

expect(instance.panX).toBe(-70);
expect(instance.panY).toBe(-35);
});

it('allows only same-origin form links and keeps URL text inside href', () => {
const instance = createInstance();
const renderLink = url => {
Expand All @@ -63,6 +83,25 @@ describe('workflow builder review fixes', () => {
expect(injected.hasAttribute('onmouseover')).toBe(false);
});

it('sanitizes form links shown inside graph nodes', () => {
const instance = createInstance();
const wrapper = document.createElement('div');
wrapper.innerHTML = instance.getNodeDescription({
type: 'form',
data: { field_count: 1, form_builder_url: '/admin/forms/?q=" onmouseover="alert(1)' },
});
const link = wrapper.querySelector('a');
expect(link.hasAttribute('onmouseover')).toBe(false);
expect(link.getAttribute('href')).toContain('/admin/forms/');
expect(link.getAttribute('rel')).toBe('noopener noreferrer');

wrapper.innerHTML = instance.getNodeDescription({
type: 'form',
data: { field_count: 1, form_builder_url: 'javascript:alert(1)' },
});
expect(wrapper.querySelector('a').getAttribute('href')).toBe('#');
});

it('moves the selected role when a group appears in two roles', () => {
const instance = createInstance();
const node = {
Expand Down
Loading