Skip to content

Honor per-strategy color when redacting PDFs and images #324

Description

@jzonthemtn

Implements the engine side of the redaction-policy schema change proposed in philterd/phisql#31: an optional color on each filter strategy that sets the PDF/image redaction bar color for spans that strategy redacts.

Blocked by philterd/phisql#31. Do not start until that RFC is accepted and the change lands in redaction-policy schema 1.2.0 (an additive, backward-compatible edit in place of the current schema version). The schema leads; Phileas follows, and the Phileas conformance test enforces that the engine implements everything the embedded schema declares.

Behavior to implement

  • A strategy may carry an optional color. When rendering a redacted PDF or image, the bar over a span uses the color of the strategy that redacted it, if set; otherwise config.pdf.redactionColor; otherwise black. Exactly one strategy applies per span, so the color is unambiguous.
  • Supported values: named colors black, white, red, orange, yellow, green, blue, gray, or a 6-digit hex string #RRGGBB. Any unrecognized or malformed value renders as black.
  • The same set + fallback apply to the existing config.pdf.redactionColor and graphical.boundingBoxes[].color, which already share the COLORS table in PdfRedactor.
  • No effect on text redaction: string output is unchanged.

Implementation notes (current code)

  • src/main/java/ai/philterd/phileas/services/strategies/AbstractFilterStrategy.java holds the shared strategy fields (redactionFormat, maskCharacter, ...). Add color here so every strategy, including DateFilterStrategy, inherits it.
  • src/main/java/ai/philterd/phileas/services/pdf/PdfRedactor.java:
    • The static COLORS map currently holds only white, black, red, yellow and does not parse hex, so blue, orange, green, gray, and any #RRGGBB currently fall back to black. Expand it to the 8 named colors and add 6-digit hex parsing, keeping the getOrDefault(..., black) fallback.
    • Fix the pre-existing scale bug in the yellow entry ({1, 1, 100 / 255F} mixes 0-1 and 0-255 component scales, while red uses {255, 0, 0}). Make the named-color RGB values use one consistent component scale.
    • Thread the redacting strategy's color onto each RedactedRectangle so the per-span bar (around lines 247-261) uses it instead of always config.pdf.getRedactionColor().
  • Embed the updated 1.2.0 schema (now including color) and update the conformance test.

Acceptance criteria

  • AbstractFilterStrategy exposes an optional color (getter/setter, @SerializedName("color")), inherited by all strategies including date.
  • PdfRedactor draws each span's bar in its redacting strategy's color when set, else config.pdf.redactionColor, else black.
  • COLORS supports all 8 named colors and 6-digit #RRGGBB hex; unrecognized or malformed values fall back to black.
  • The yellow named-color RGB scale bug is fixed and all named colors use a consistent component scale.
  • config.pdf.redactionColor and graphical.boundingBoxes[].color also resolve against the expanded set (shared table).
  • Text-only redaction output is byte-identical with and without color set.
  • Embedded redaction-policy schema is 1.2.0 (the revision that adds color) and the conformance test passes.
  • PdfRedactorTest covers per-strategy color, the named palette, 6-digit hex, and black fallback for an unknown value.
  • Documentation under docs/docs/ is updated for the new strategy property and the supported-color set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions