Compare commits

..
Author SHA1 Message Date
Frooodle bb37d5ae07 Merge branch 'main' into security/server-image-cves 2026-07-13 09:24:04 +01:00
Frooodle e7a81092c5 merge main 2026-07-10 10:27:03 +01:00
Frooodle e8f76aa2d9 merge main 2026-07-06 18:54:14 +01:00
Frooodle ae450fa878 merge main 2026-07-02 09:44:37 +01:00
Frooodle 4a792c54ef merge main 2026-07-01 08:50:20 +01:00
Frooodle ecb1700c08 merge main 2026-06-30 08:39:35 +01:00
Frooodle fc99de2d53 merge main 2026-06-29 11:23:47 +01:00
Frooodle e099e0302b merge main 2026-06-27 08:44:15 +01:00
Anthony Stirling 6764cf1eff Patch CVEs in server image deps and base image 2026-06-25 10:30:46 +01:00
17 changed files with 54 additions and 449 deletions
+36
View File
@@ -43,6 +43,17 @@ ext {
jwtVersion = "0.13.0"
awsSdkVersion = "2.44.12"
testcontainersMinioVersion = "1.21.4"
// Security CVE overrides for Spring Boot 4 BOM-managed transitives
nettyVersion = "4.2.15.Final"
jackson2Version = "2.22.0"
// jackson-annotations ships 2-component versions (2.22, not 2.22.0)
jackson2AnnotationsVersion = "2.22"
// Jackson 3 (tools.jackson) used by Spring Boot 4; 3.1.4 patches CVE-2026-54512..54518
jackson3Version = "3.1.4"
postgresqlVersion = "42.7.11"
// velocity-engine-core 2.3 (via shib-velocity SAML stack) shades a vulnerable
// commons-io 2.8.0 (CVE-2024-47554) into its jar; 2.4.1 no longer shades it
velocityVersion = "2.4.1"
// junit-platform-launcher version managed by Spring Boot BOM
modernJavaVersion = 25
}
@@ -222,10 +233,33 @@ subprojects {
resolutionStrategy.force "org.apache.commons:commons-lang3:${commonsLang3}"
// CVE-2024-47554: commons-io DoS prevention
resolutionStrategy.force "commons-io:commons-io:${commonsIoVersion}"
// CVE-2024-47554: velocity-engine-core 2.3 shades commons-io 2.8.0; 2.4.1 unshades it
resolutionStrategy.force "org.apache.velocity:velocity-engine-core:${velocityVersion}"
// Keep BouncyCastle modules aligned to avoid runtime linkage errors
resolutionStrategy.force "org.bouncycastle:bcprov-jdk18on:${bouncycastleVersion}"
resolutionStrategy.force "org.bouncycastle:bcpkix-jdk18on:${bouncycastleVersion}"
resolutionStrategy.force "org.bouncycastle:bcutil-jdk18on:${bouncycastleVersion}"
resolutionStrategy.eachDependency { details ->
// Netty 4.2.x: CVE-2026-44249/45416/45673/45674/47244/47691/48043/50010/50020/50560
// /42579/42580/42581/42583/42584/42585/42587/41417 - force 4.2.15.Final across all modules
if (details.requested.group == "io.netty") {
details.useVersion nettyVersion
details.because "CVE-2026 netty fixes (>=4.2.15.Final)"
}
// Jackson 2.x: CVE-2026-54512/54513/54514/54515/54516/54517/54518 - force 2.22.0.
// jackson-annotations uses 2-component versions (2.22), unlike core/databind (2.22.0).
if (details.requested.group.startsWith("com.fasterxml.jackson")) {
details.useVersion(details.requested.name == "jackson-annotations"
? jackson2AnnotationsVersion : jackson2Version)
details.because "CVE-2026-54512..54518 jackson 2.x fixes (>=2.22.0)"
}
// Jackson 3 (tools.jackson) ships with Spring Boot 4; same CVE-2026-54512..54518
// family is fixed in 3.1.4 (stays in Spring Boot's 3.1.x line).
if (details.requested.group.startsWith("tools.jackson")) {
details.useVersion jackson3Version
details.because "CVE-2026-54512..54518 jackson 3.x fixes (>=3.1.4)"
}
}
}
dependencyManagement {
@@ -235,6 +269,8 @@ subprojects {
dependencies {
// Override BOM-managed commons-lang3 for CVE-2025-48924 fix
dependency "org.apache.commons:commons-lang3:$commonsLang3"
// CVE-2026-42198: Spring Boot 4 BOM pins postgresql 42.7.10; override to patched 42.7.11
dependency "org.postgresql:postgresql:$postgresqlVersion"
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
# Stirling-PDF backend-only image — JAR built with -PbuildWithFrontend=false, UI ships separately.
ARG BASE_VERSION=1.0.2
ARG BASE_VERSION=1.0.4
ARG BASE_IMAGE=stirlingtools/stirling-pdf-base:${BASE_VERSION}
# Stage 1: Build the Java application (backend only, no frontend)
+10 -6
View File
@@ -5,7 +5,7 @@
ARG TARGETPLATFORM
# Stage 1: Build and strip Calibre
FROM ubuntu:noble@sha256:c4a8d5503dfb2a3eb8ab5f807da5bc69a85730fb49b5cfca2330194ebcc41c7b AS calibre-build
FROM ubuntu:noble@sha256:786a8b558f7be160c6c8c4a54f9a57274f3b4fb1491cf65146521ae77ff1dc54 AS calibre-build
ARG TARGETPLATFORM
ARG CALIBRE_VERSION=9.4.0
ARG CALIBRE_STRIP_WEBENGINE=false
@@ -270,7 +270,7 @@ RUN if [ "${CALIBRE_STRIP_WEBENGINE}" = "true" ]; then \
# Stage 2: Build Ghostscript from source
FROM ubuntu:noble@sha256:c4a8d5503dfb2a3eb8ab5f807da5bc69a85730fb49b5cfca2330194ebcc41c7b AS gs-build
FROM ubuntu:noble@sha256:786a8b558f7be160c6c8c4a54f9a57274f3b4fb1491cf65146521ae77ff1dc54 AS gs-build
ARG TARGETPLATFORM
ARG GS_VERSION=10.06.0
@@ -294,7 +294,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
# Stage 3: Build PDF Tools (QPDF and ImageMagick 7)
FROM ubuntu:noble@sha256:c4a8d5503dfb2a3eb8ab5f807da5bc69a85730fb49b5cfca2330194ebcc41c7b AS pdf-tools-build
FROM ubuntu:noble@sha256:786a8b558f7be160c6c8c4a54f9a57274f3b4fb1491cf65146521ae77ff1dc54 AS pdf-tools-build
ARG TARGETPLATFORM
ARG QPDF_VERSION=12.3.2
ARG IM_VERSION=7.1.2-13
@@ -339,7 +339,7 @@ RUN mkdir -p /magick-export/usr/bin \
# Stage 4: Build Python venv
FROM ubuntu:noble@sha256:c4a8d5503dfb2a3eb8ab5f807da5bc69a85730fb49b5cfca2330194ebcc41c7b AS python-venv-build
FROM ubuntu:noble@sha256:786a8b558f7be160c6c8c4a54f9a57274f3b4fb1491cf65146521ae77ff1dc54 AS python-venv-build
ARG TARGETPLATFORM
ARG UNOSERVER_VERSION=3.6
@@ -352,7 +352,8 @@ RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
python3 -m venv /opt/venv --system-site-packages && \
/opt/venv/bin/pip install --no-cache-dir --prefer-binary --only-binary=:all: \
weasyprint pdf2image opencv-python-headless ocrmypdf \
cryptography \
"cryptography>=48.0.1" \
"lxml>=6.1.0" \
"unoserver==${UNOSERVER_VERSION}" && \
find /opt/venv -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
find /opt/venv \( -name '*.pyc' -o -name '*.pyi' \) -delete 2>/dev/null || true && \
@@ -364,7 +365,7 @@ RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
# Final runtime image - the actual base image
FROM eclipse-temurin:25-jre-noble@sha256:b27ca47660a8fa837e47a8533b9b1a3a430295cf29ca28d91af4fd121572dc29 AS runtime
FROM eclipse-temurin:25-jre-noble@sha256:f9bd8815e73632c22985ebb133ec49b9fc4ad5ffe0657594ac02748ad0431ab7 AS runtime
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
@@ -382,6 +383,9 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get install -y --no-install-recommends software-properties-common; \
add-apt-repository -y ppa:libreoffice/ppa; \
apt-get update; \
# Security: upgrade base-image packages to latest noble patches (reduces deb CVEs
# in openssl, perl, libxml2, gnutls, cups, curl, etc. inherited from the runtime base)
apt-get upgrade -y; \
apt-get install -y --no-install-recommends \
# Core tools
ca-certificates tzdata tini bash fontconfig curl \
+2 -2
View File
@@ -1,7 +1,7 @@
# Stirling-PDF - Full version (embedded frontend)
# Uses pre-built base image for fast builds
ARG BASE_VERSION=1.0.2
ARG BASE_VERSION=1.0.4
ARG BASE_IMAGE=stirlingtools/stirling-pdf-base:${BASE_VERSION}
# Stage 1: Build the Java application and frontend
@@ -59,7 +59,7 @@ RUN JPDFIUM_PLATFORM="$([ "$TARGETARCH" = arm64 ] && echo linux-arm64 || echo li
--no-daemon
# Stage 2: Extract Spring Boot Layers
FROM eclipse-temurin:25-jre-noble@sha256:b27ca47660a8fa837e47a8533b9b1a3a430295cf29ca28d91af4fd121572dc29 AS jar-extract
FROM eclipse-temurin:25-jre-noble@sha256:f9bd8815e73632c22985ebb133ec49b9fc4ad5ffe0657594ac02748ad0431ab7 AS jar-extract
WORKDIR /tmp
COPY --from=app-build /app/app/core/build/libs/*.jar app.jar
RUN java -Djarmode=tools -jar app.jar extract --layers --destination /layers
+1 -1
View File
@@ -2,7 +2,7 @@
# Extra fonts for air-gapped environments
# Uses pre-built base image for fast builds
ARG BASE_VERSION=1.0.2
ARG BASE_VERSION=1.0.4
ARG BASE_IMAGE=stirlingtools/stirling-pdf-base:${BASE_VERSION}
# Stage 1: Build the Java application and frontend
+2 -1
View File
@@ -55,7 +55,7 @@ RUN JPDFIUM_PLATFORM="$([ "$TARGETARCH" = arm64 ] && echo linux-arm64 || echo li
# Stage 2: Runtime image
# glibc base (not Alpine/musl): JPDFium's PDFium natives are glibc-linked.
FROM eclipse-temurin:25-jre-noble@sha256:b27ca47660a8fa837e47a8533b9b1a3a430295cf29ca28d91af4fd121572dc29
FROM eclipse-temurin:25-jre-noble@sha256:f9bd8815e73632c22985ebb133ec49b9fc4ad5ffe0657594ac02748ad0431ab7
ENV DEBIAN_FRONTEND=noninteractive \
LANG=C.UTF-8 \
@@ -99,6 +99,7 @@ ENV VERSION_TAG=$VERSION_TAG \
RUN mkdir -p $HOME /configs /logs /customFiles /pipeline/watchedFolders /pipeline/finishedFolders /storage /tmp/stirling-pdf /tmp/stirling-pdf/heap_dumps && \
mkdir -p /usr/share/fonts/opentype/noto && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
ca-certificates \
tzdata \
@@ -230,8 +230,6 @@ title = "How to add images"
move = "Move Image"
pause = "Pause placement"
place = "Place Image"
placeMultiple = "Stay in placement mode after each placement"
placeMultipleDesc = "Place several images in a row instead of exiting after the first."
resume = "Resume placement"
[addImage.results]
@@ -447,8 +445,6 @@ title = "How to add text"
move = "Move Text"
pause = "Pause placement"
place = "Place Text"
placeMultiple = "Stay in placement mode after each placement"
placeMultipleDesc = "Place several text stamps in a row instead of exiting after the first."
resume = "Resume placement"
[addText.results]
@@ -9284,8 +9280,6 @@ title = "How to add signature"
move = "Move Signature"
pause = "Pause placement"
place = "Place Signature"
placeMultiple = "Stay in placement mode after each placement"
placeMultipleDesc = "Place several signatures in a row instead of exiting after the first."
resume = "Resume placement"
[sign.results]
@@ -8,7 +8,6 @@ import {
Tooltip,
Group,
Box,
Checkbox,
} from "@mantine/core";
import { Button } from "@app/ui/Button";
import { SegmentedControl } from "@app/ui/SegmentedControl";
@@ -35,7 +34,6 @@ import {
AddSignatureResult,
} from "@app/hooks/tools/sign/useSavedSignatures";
import { SavedSignaturesSection } from "@app/components/tools/sign/SavedSignaturesSection";
import { shouldPausePlacementAfterExit } from "@app/components/tools/sign/placementMode";
import { buildSignaturePreview } from "@app/utils/signaturePreview";
type SignatureDrafts = {
@@ -92,13 +90,7 @@ const SignSettings = ({
defaultSignatureSource,
}: SignSettingsProps) => {
const { t } = useTranslation();
const {
isPlacementMode,
signaturesApplied,
historyApiRef,
placeMultiple,
setPlaceMultiple,
} = useSignature();
const { isPlacementMode, signaturesApplied, historyApiRef } = useSignature();
const { activeFileIndex } = useViewer();
const [historyAvailability, setHistoryAvailability] = useState({
canUndo: false,
@@ -829,34 +821,6 @@ const SignSettings = ({
onParameterChange,
]);
// After a single placement (when "place multiple" is off) the
// SignatureAPIBridge drops out of placement mode. Without pausing here, the
// auto-activate effect below would immediately pull the user back into
// placement mode - so single placement would never stick and the "place
// multiple" checkbox would appear to do nothing.
const wasPlacementModeRef = useRef(isPlacementMode);
useEffect(() => {
const shouldPause = shouldPausePlacementAfterExit({
wasInPlacementMode: wasPlacementModeRef.current,
isInPlacementMode: isPlacementMode,
placeMultiple,
signaturesApplied,
placementEnabled: shouldEnablePlacement,
alreadyPaused: isPlacementManuallyPaused,
});
wasPlacementModeRef.current = isPlacementMode;
if (shouldPause) {
setPlacementManuallyPaused(true);
}
}, [
isPlacementMode,
placeMultiple,
signaturesApplied,
shouldEnablePlacement,
isPlacementManuallyPaused,
]);
useEffect(() => {
if (!shouldEnablePlacement) {
if (isPlacementMode) {
@@ -1233,20 +1197,6 @@ const SignSettings = ({
<Box style={{ marginLeft: "auto" }}>{placementToggleControl}</Box>
</Group>
<Checkbox
checked={placeMultiple}
onChange={(event) => setPlaceMultiple(event.currentTarget.checked)}
label={translate(
"mode.placeMultiple",
"Stay in placement mode after each placement",
)}
description={translate(
"mode.placeMultipleDesc",
"Place several stamps in a row instead of exiting after the first.",
)}
disabled={disabled}
/>
<Alert color={placementAlert.color} title={placementAlert.title}>
<Text size="sm">{placementAlert.message}</Text>
</Alert>
@@ -1,71 +0,0 @@
import { describe, expect, it } from "vitest";
import { shouldPausePlacementAfterExit } from "@app/components/tools/sign/placementMode";
const baseParams = {
wasInPlacementMode: true,
isInPlacementMode: false,
placeMultiple: false,
signaturesApplied: false,
placementEnabled: true,
alreadyPaused: false,
};
describe("shouldPausePlacementAfterExit", () => {
it("pauses after a single placement exits placement mode", () => {
expect(shouldPausePlacementAfterExit(baseParams)).toBe(true);
});
it("does not pause while still in placement mode", () => {
expect(
shouldPausePlacementAfterExit({
...baseParams,
isInPlacementMode: true,
}),
).toBe(false);
});
it("does not pause when placement mode was never active", () => {
expect(
shouldPausePlacementAfterExit({
...baseParams,
wasInPlacementMode: false,
}),
).toBe(false);
});
it("does not pause when 'place multiple' is enabled", () => {
expect(
shouldPausePlacementAfterExit({
...baseParams,
placeMultiple: true,
}),
).toBe(false);
});
it("does not pause once signatures have been applied", () => {
expect(
shouldPausePlacementAfterExit({
...baseParams,
signaturesApplied: true,
}),
).toBe(false);
});
it("does not pause when placement is disabled", () => {
expect(
shouldPausePlacementAfterExit({
...baseParams,
placementEnabled: false,
}),
).toBe(false);
});
it("does not re-pause when already paused", () => {
expect(
shouldPausePlacementAfterExit({
...baseParams,
alreadyPaused: true,
}),
).toBe(false);
});
});
@@ -1,39 +0,0 @@
interface PausePlacementParams {
/** Whether placement mode was active on the previous render. */
wasInPlacementMode: boolean;
/** Whether placement mode is active now. */
isInPlacementMode: boolean;
/** User opted into dropping several stamps in a row. */
placeMultiple: boolean;
/** True once placed signatures have been flattened/applied to the document. */
signaturesApplied: boolean;
/** Whether a signature is configured and placement is allowed. */
placementEnabled: boolean;
/** Whether placement is already manually paused. */
alreadyPaused: boolean;
}
/**
* Whether placement should be paused after the viewer auto-exits placement mode.
*
* The SignatureAPIBridge drops out of placement mode after a single stamp is
* placed (unless "place multiple" is on). Without pausing, SignSettings' own
* auto-activate effect would immediately re-enter placement mode, so single
* placement would never stick and the "place multiple" checkbox would appear to
* do nothing. We only react to the placement-mode exit (the bridge already
* limits auto-exit to stamp placements, never mid-signature ink strokes).
*/
export function shouldPausePlacementAfterExit(
params: PausePlacementParams,
): boolean {
const justExitedPlacement =
params.wasInPlacementMode && !params.isInPlacementMode;
return (
justExitedPlacement &&
!params.placeMultiple &&
!params.signaturesApplied &&
params.placementEnabled &&
!params.alreadyPaused
);
}
@@ -16,7 +16,6 @@ import type {
import type { SignParameters } from "@app/hooks/tools/sign/useSignParameters";
import { useViewer } from "@app/contexts/ViewerContext";
import { useDocumentReady } from "@app/components/viewer/hooks/useDocumentReady";
import { shouldAutoExitPlacement } from "@app/components/viewer/signaturePlacement";
/**
* Connects the PDF signature (stamp/ink) tools to the shared ViewerContext and SignatureContext.
@@ -186,16 +185,7 @@ export const SignatureAPIBridge = forwardRef<
isPlacementMode,
placementPreviewSize,
setSignaturesApplied,
placeMultiple,
setPlacementMode,
} = useSignature();
// Track latest placeMultiple in a ref so the long-lived onAnnotationEvent
// subscription always reads the current value without re-subscribing on every
// toggle change (which would race with mid-flight create events).
const placeMultipleRef = useRef(placeMultiple);
useEffect(() => {
placeMultipleRef.current = placeMultiple;
}, [placeMultiple]);
const { getZoomState, registerImmediateZoomUpdate } = useViewer();
const documentReady = useDocumentReady();
const [currentZoom, setCurrentZoom] = useState(
@@ -565,11 +555,6 @@ export const SignatureAPIBridge = forwardRef<
// Mark signatures as not applied when a new signature is placed
if (event.type === "create") {
setSignaturesApplied(false);
if (shouldAutoExitPlacement(annotation, placeMultipleRef.current)) {
annotationApi.setActiveTool(null);
setPlacementMode(false);
}
}
const directData =
@@ -591,13 +576,7 @@ export const SignatureAPIBridge = forwardRef<
return () => {
unsubscribe?.();
};
}, [
annotationApi,
storeImageData,
setSignaturesApplied,
setPlacementMode,
documentReady,
]);
}, [annotationApi, storeImageData, setSignaturesApplied, documentReady]);
useEffect(() => {
if (!isPlacementMode || !documentReady) {
@@ -1,50 +0,0 @@
import { describe, expect, it } from "vitest";
import { PdfAnnotationSubtype } from "@embedpdf/models";
import { shouldAutoExitPlacement } from "@app/components/viewer/signaturePlacement";
describe("shouldAutoExitPlacement", () => {
it("returns true for a stamp annotation when placeMultiple is false", () => {
expect(
shouldAutoExitPlacement({ type: PdfAnnotationSubtype.STAMP }, false),
).toBe(true);
});
it("returns false for a stamp annotation when placeMultiple is true", () => {
expect(
shouldAutoExitPlacement({ type: PdfAnnotationSubtype.STAMP }, true),
).toBe(false);
});
it("returns false for an ink-stroke annotation regardless of placeMultiple", () => {
expect(
shouldAutoExitPlacement({ type: PdfAnnotationSubtype.INK }, false),
).toBe(false);
expect(
shouldAutoExitPlacement({ type: PdfAnnotationSubtype.INK }, true),
).toBe(false);
});
it("falls back to annotation.object.type when annotation.type is missing", () => {
expect(
shouldAutoExitPlacement(
{ object: { type: PdfAnnotationSubtype.STAMP } },
false,
),
).toBe(true);
});
it("returns false when neither annotation.type nor object.type is present", () => {
expect(shouldAutoExitPlacement({}, false)).toBe(false);
expect(shouldAutoExitPlacement(null, false)).toBe(false);
expect(shouldAutoExitPlacement(undefined, false)).toBe(false);
});
it("returns false for FREETEXT, HIGHLIGHT, and other non-stamp types", () => {
expect(
shouldAutoExitPlacement({ type: PdfAnnotationSubtype.FREETEXT }, false),
).toBe(false);
expect(
shouldAutoExitPlacement({ type: PdfAnnotationSubtype.HIGHLIGHT }, false),
).toBe(false);
});
});
@@ -1,23 +0,0 @@
import { PdfAnnotationSubtype } from "@embedpdf/models";
interface AutoExitCandidate {
type?: unknown;
object?: { type?: unknown };
}
/**
* Whether placement mode should auto-exit after a `create` annotation event.
*
* Only stamp annotations trigger auto-exit. Ink strokes also raise `create`
* events, but a multi-stroke signature would break if we deactivated the tool
* after the first stroke. When `placeMultiple` is true the user has opted in
* to dropping several stamps in a row, so we never auto-exit.
*/
export function shouldAutoExitPlacement(
annotation: AutoExitCandidate | null | undefined,
placeMultiple: boolean,
): boolean {
if (placeMultiple) return false;
const type = annotation?.type ?? annotation?.object?.type ?? null;
return type === PdfAnnotationSubtype.STAMP;
}
@@ -23,10 +23,6 @@ interface SignatureState {
signaturesApplied: boolean;
// Size (in screen units) we want newly placed signatures to use
placementPreviewSize: { width: number; height: number } | null;
// When false (default), placement mode auto-exits after a single stamp is
// dropped so users don't accidentally place duplicates. When true, the user
// opted into staying in placement mode and can drop multiple stamps in a row.
placeMultiple: boolean;
}
// Signature actions interface
@@ -46,7 +42,6 @@ interface SignatureActions {
setPlacementPreviewSize: (
size: { width: number; height: number } | null,
) => void;
setPlaceMultiple: (enabled: boolean) => void;
}
// Combined context interface
@@ -67,7 +62,6 @@ const initialState: SignatureState = {
isPlacementMode: false,
signaturesApplied: true, // Start as true (no signatures placed yet)
placementPreviewSize: null,
placeMultiple: false,
};
// Provider component
@@ -180,13 +174,6 @@ export const SignatureProvider: React.FC<{ children: ReactNode }> = ({
[],
);
const setPlaceMultiple = useCallback((enabled: boolean) => {
setState((prev) => ({
...prev,
placeMultiple: enabled,
}));
}, []);
// No auto-activation - all modes use manual buttons
const contextValue: SignatureContextValue = {
@@ -207,7 +194,6 @@ export const SignatureProvider: React.FC<{ children: ReactNode }> = ({
getImageData,
setSignaturesApplied,
setPlacementPreviewSize,
setPlaceMultiple,
};
return (
@@ -1,90 +0,0 @@
import { test, expect } from "@app/tests/helpers/stub-test-base";
import { uploadFiles, dismissTourTooltip } from "@app/tests/helpers/ui-helpers";
import type { Page } from "@playwright/test";
import path from "path";
const SAMPLE_PDF = path.join(
import.meta.dirname,
"../test-fixtures/sample.pdf",
);
const FIRST_PAGE = '[data-page-index="0"]';
const pauseButton = (page: Page) =>
page.getByRole("button", { name: /pause placement/i });
const resumeButton = (page: Page) =>
page.getByRole("button", { name: /resume placement/i });
/**
* Reviewer report: on the stamp-style tools the "place multiple" checkbox
* "doesn't do anything". Single placement never stuck because, after the
* viewer auto-exited placement mode, SignSettings' auto-activate effect
* immediately re-entered it. These tests drive a real text-stamp placement and
* assert the placement toggle settles into the correct state:
* - box off (default): placement exits after one stamp (Resume offered)
* - box on: placement stays active across stamps (Pause stays offered)
*
* Unit coverage of the decision lives in
* components/tools/sign/placementMode.test.ts; this spec guards the end-to-end
* UX so future refactors don't silently regress it.
*/
test.describe("AddText place-multiple behaviour", () => {
async function enterPlacementMode(page: Page): Promise<void> {
await page.goto("/add-text");
await page.waitForLoadState("domcontentloaded");
await uploadFiles(page, SAMPLE_PDF);
await dismissTourTooltip(page);
// Wait for the PDF to render before configuring the signature. Placement is
// activated on text change and only fires once, so the viewer (and its
// SignatureAPIBridge) must be mounted first or the activation is lost.
await expect(page.locator(FIRST_PAGE).first()).toBeVisible({
timeout: 30_000,
});
// Configuring a text signature auto-activates placement mode.
await page
.getByPlaceholder("Enter the text you want to add")
.fill("Reviewer Test");
// Placement active -> the toggle offers "Pause placement".
await expect(pauseButton(page)).toBeVisible({ timeout: 20_000 });
}
test("single placement (default) exits placement mode", async ({ page }) => {
await enterPlacementMode(page);
await page
.locator(FIRST_PAGE)
.first()
.click({ position: { x: 150, y: 150 } });
// Wait past the 60ms auto-activate window: with the fix the tool stays
// exited; without it placement bounces straight back into "Pause" mode.
await page.waitForTimeout(750);
await expect(resumeButton(page)).toBeVisible();
await expect(pauseButton(page)).toBeHidden();
});
test("'place multiple' keeps placement active after a placement", async ({
page,
}) => {
await enterPlacementMode(page);
await page
.getByRole("checkbox", {
name: /stay in placement mode after each placement/i,
})
.check();
await page
.locator(FIRST_PAGE)
.first()
.click({ position: { x: 150, y: 150 } });
await page.waitForTimeout(750);
// Still placing: Pause stays offered, Resume never appears.
await expect(pauseButton(page)).toBeVisible();
await expect(resumeButton(page)).toBeHidden();
});
});
@@ -1,58 +0,0 @@
import { test, expect } from "@app/tests/helpers/stub-test-base";
import { uploadFiles } from "@app/tests/helpers/ui-helpers";
import path from "path";
const SAMPLE_PDF = path.join(
import.meta.dirname,
"../test-fixtures/sample.pdf",
);
const TOOLS_WITH_PLACEMENT_TOGGLE: Array<{ name: string; url: string }> = [
{ name: "AddImage", url: "/add-image" },
{ name: "AddText", url: "/add-text" },
{ name: "Sign", url: "/sign" },
];
/**
* The "place multiple" checkbox is rendered by SignSettings for the three
* stamp-style tools (AddImage / AddText / Sign). Behaviour contract:
* - Default unchecked: placement mode auto-exits after one stamp
* - Toggling on keeps the user in placement mode across multiple stamps
* Helper logic is unit-tested in signaturePlacement.test.ts; this spec
* verifies the UI contract end-to-end so future SignSettings refactors do
* not silently regress the default UX.
*/
for (const tool of TOOLS_WITH_PLACEMENT_TOGGLE) {
test.describe(`${tool.name} placement toggle`, () => {
test("renders the 'place multiple' checkbox unchecked by default", async ({
page,
}) => {
await page.goto(tool.url);
await page.waitForLoadState("domcontentloaded");
await uploadFiles(page, SAMPLE_PDF);
const placeMultiple = page.getByRole("checkbox", {
name: /stay in placement mode after each placement/i,
});
await expect(placeMultiple).toBeVisible({ timeout: 15_000 });
await expect(placeMultiple).not.toBeChecked();
});
test("toggling the 'place multiple' checkbox flips its state", async ({
page,
}) => {
await page.goto(tool.url);
await page.waitForLoadState("domcontentloaded");
await uploadFiles(page, SAMPLE_PDF);
const placeMultiple = page.getByRole("checkbox", {
name: /stay in placement mode after each placement/i,
});
await expect(placeMultiple).toBeVisible({ timeout: 15_000 });
await placeMultiple.check();
await expect(placeMultiple).toBeChecked();
await placeMultiple.uncheck();
await expect(placeMultiple).not.toBeChecked();
});
});
}
@@ -73,8 +73,6 @@ export const createStampTool = (config: StampToolConfig) => {
signatureApiRef,
getImageData,
setSignaturesApplied,
setPlacementMode,
setPlaceMultiple,
} = useSignature();
const { consumeFiles, selectors } = useFileContext();
const {
@@ -145,18 +143,6 @@ export const createStampTool = (config: StampToolConfig) => {
setSignatureConfig(base.params.parameters);
}, [base.params.parameters, setSignatureConfig]);
// When the tool unmounts (user navigates to a different tool), leave
// placement mode and clear any active stamp/ink tool. Otherwise the
// placement state and the "place signature" cursor leak into whatever the
// user opens next.
useEffect(() => {
return () => {
handleDeactivateSignature();
setPlacementMode(false);
setPlaceMultiple(false);
};
}, [handleDeactivateSignature, setPlacementMode, setPlaceMultiple]);
const handleSaveToSystem = useCallback(async () => {
try {
unregisterUnsavedChangesChecker();