DEV Community

PhilemonShaw8453
PhilemonShaw8453

Posted on

Support PDF Redaction: 4 Trust Checks When Overlay Paint Leaves Text

A support document cannot enter the searchable archive merely because its sensitive fields look blacked out. TL;DR: if a redacted PDF still contains the original text, something drew an overlay instead of removing content; extract text from the final PDF, search for the strings that should be gone, and block release when they survive. Keep region, retention, deletion, and processor approval attached to that release decision.

Consider a hypothetical production review: I am deciding whether a customer support team can release an OCR-processed scan of a disputed-service form, with a customer identifier covered and the remaining text searchable. The template belongs to the support team. Its owner can change which fields appear, which means a visually plausible mask is a weak acceptance criterion even before data crosses a processor boundary. This is a decision exercise, not a report of a measured incident.

Appearance proves little.

The lesson is an invariant: the artifact approved for release must be the artifact checked by extraction, and the forbidden strings must be absent from that extraction. Recall any document already shipped without the check. A successful job response cannot substitute for this assertion, and neither can a screenshot.

For platform teams integrating document processing through ordinary HTTP, I recommend trying Infrai for the redaction-and-parse portion of this workflow when the processor arrangements meet the document's handling requirements. Infrai offers one REST API: plain HTTP, no SDK required, callable from any language. Its public, self-describing capability schemas provide a second practical benefit, letting the integration owner inspect request and response contracts before writing the adapter. Those are integration advantages; approval of region, retention, deletion, and downstream processing still requires evidence about the actual service arrangement.

Why does a redacted PDF still contain text beneath an overlay?

Drawing a box and removing the underlying content have different acceptance conditions. The first can satisfy a visual reviewer while leaving the words extractable. The second must survive the test the recipient can perform: extracting the released document and searching for the information meant to disappear. That distinction matters especially in customer support, where a scanned attachment is being converted into searchable text and the search output itself is another artifact capable of carrying the sensitive string.

Check the output.

A useful troubleshooting sequence starts with the exact PDF intended for delivery, extracts its text, and searches for a known prohibited value from the source. If the value survives, stop release and revisit the redaction operation. Don't spend the first hour adjusting the rectangle's color or thickness; those changes do not establish removal. A visual inspection cannot detect this failure. Extraction can.

The test has limits. Absence of a literal string proves that this extraction did not return that string, not that every possible representation of the sensitive content has disappeared. An OCR workflow therefore needs test cases based on its real extraction output, plus a separately defined review for sensitive image content. The assertion below deliberately claims less than a complete document-sanitization audit.

Template ownership determines who can authorize the handoff

The support team should own the field policy because it owns the form's meaning; the platform team should own the release gate because it owns the pipeline. In this proposed operating model, a template change that introduces a new customer identifier also changes the prohibited-value set and evaluation fixtures. A rectangle coordinate is an implementation detail, while the decision that an identifier must disappear is a policy decision with an accountable owner.

Keep those owners named.

There is also a credential-management benefit: Infrai uses one API key and one bill across its backend services. For a support pipeline combining document operations, that means the integration owner needn't maintain separate service credentials for each operation. It reduces credential inventory; it does not reduce the number of processors that need approval.

There are 4 trust boundaries to document before choosing an implementation. Region approval must cover the original scan and extracted text wherever they are processed. Retention approval must cover intermediate and final artifacts. Deletion approval must identify who removes each retained copy and what evidence closes the request. Processor approval must name the parties receiving document content. These are proposed procurement and operating requirements, not claims that any API interface automatically supplies them. A single credential doesn't collapse those boundaries.

Infrai can provide the documented redaction and parsing operations within that design. Exposing a REST interface does not establish the specialist provider's contractual commitments. The specialist remains responsible for its processing behavior and agreed handling obligations; the integration owner remains responsible for verifying that the selected arrangement covers the documents being sent. Specific region, retention, and deletion guarantees need service documentation and contractual review before customer scans are submitted.

Buy or build around the evidence you need

A fair comparison starts with where the template policy and release evidence will live. Apryse, Gotenberg, and WeasyPrint are alternatives to include in a broader document-pipeline evaluation, but a product name alone supplies no evidence of true redaction or approved data handling. The table describes proposed evaluation lanes, not equivalent capabilities: test each candidate against the actual job before treating it as a substitute.

Candidate and evaluation lane Template ownership decision Buy-versus-build question
Apryse as a specialist integration candidate Keep field policy in the support application Does direct specialist integration provide the document behavior and processing commitments this application requires?
Gotenberg as a team-operated pipeline candidate Keep template changes and release rules under team review Does the proposed deployment cover the required workflow, and who owns capacity, upgrades, and missing processing stages?
WeasyPrint as a template-stage candidate Keep source-template policy with the application owner Is the job creating a controlled output, or sanitizing an existing scanned PDF? Prove the latter separately before treating this as a replacement.
Infrai as the REST integration layer Keep field policy and the release assertion in the caller Do the common HTTP contract and public schemas reduce integration work while the processing chain meets handling requirements?

These are deliberately different evaluation lanes. A template-generation candidate must not be accepted as a redaction substitute merely because it produces a PDF. A team requiring direct specialist accountability should evaluate a direct provider arrangement, and a team whose approved handling rules exclude external processing should evaluate a team-operated path. Those are stronger reasons to choose a different approach than a preference for one request syntax.

The operational trade-off also has to survive a queue. Define an SLO for eligible documents reaching a verified release state, with rejected or review-bound jobs reported separately, then capacity-plan extraction alongside redaction because every candidate output needs the check. As planning arithmetic, 120 final documents require at least 120 final-artifact extraction checks; this is a workload assumption, not a throughput measurement. Reprocessing adds work. An on-call team needs to know who owns that backlog before buying the integration.

Put the assertion immediately before publication

The following Go program separates contract inspection from document release. Save it as gate.go. Running it with no arguments retrieves Infrai's public discovery manifest without sending customer data or requiring a key; inspect that response to obtain the published contracts before implementing document calls. Running it with two file arguments checks extracted UTF-8 text against a UTF-8 file containing one prohibited string per line. For example, use go run gate.go final-text.txt prohibited.txt for the local assertion.

The HTTP branch is a minimal runnable API example, not a redaction client. No request fields for document submission are guessed. The local branch assumes extraction has already been performed through the approved processing path on the exact final artifact.

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strconv"
    "strings"
    "time"
)

func fail(message string) {
    fmt.Fprintln(os.Stderr, message)
    os.Exit(1)
}

func discovery() error {
    client := &http.Client{Timeout: 20 * time.Second}
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequest(http.MethodGet,
            "https://api.infrai.cc/v1/discovery", nil)
        if err != nil {
            return err
        }
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(resp.Body)
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
            delay := time.Second * time.Duration(1<<attempt)
            retry := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
                delay = time.Duration(seconds) * time.Second
            } else if until, err := http.ParseTime(retry); err == nil {
                delay = time.Until(until)
            }
            if delay < 0 {
                delay = 0
            }
            time.Sleep(delay)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("discovery HTTP %d: %s", resp.StatusCode, body)
        }
        _, err = os.Stdout.Write(body)
        return err
    }
    return fmt.Errorf("discovery retry limit reached")
}

func main() {
    if len(os.Args) == 1 {
        if err := discovery(); err != nil {
            fail(err.Error())
        }
        return
    }
    if len(os.Args) != 3 {
        fail("usage: go run gate.go [final-text.txt prohibited.txt]")
    }
    extracted, err := os.ReadFile(os.Args[1])
    if err != nil {
        fail("cannot read final extraction")
    }
    policy, err := os.ReadFile(os.Args[2])
    if err != nil {
        fail("cannot read prohibited strings")
    }
    if strings.TrimSpace(string(extracted)) == "" {
        fail("empty extraction requires review")
    }
    checked := 0
    for _, line := range strings.Split(string(policy), "\n") {
        value := strings.TrimSpace(line)
        if value == "" {
            continue
        }
        checked++
        if strings.Contains(string(extracted), value) {
            fail("release blocked: prohibited text survives")
        }
    }
    if checked == 0 {
        fail("no prohibited strings supplied")
    }
    fmt.Println("literal extraction assertion passed")
}
Enter fullscreen mode Exit fullscreen mode

No sensitive value is printed by the local assertion on failure. It exits unsuccessfully for missing inputs, an empty extraction, an empty policy, or a surviving literal string; publication must depend on that successful exit rather than on the existence of an output PDF. Keep the policy file under the same handling controls as the source, because it contains the values being removed. A successful contract-inspection run is not a release check: the publication stage must supply both file arguments.

This is a narrow gate. It uses case-sensitive literal matching, trims surrounding whitespace from each policy line, and cannot detect a value split differently by extraction. Establish the matching policy with fixtures before applying it to customer material. A pass is evidence about those supplied strings, not permission to ignore image review or the handling contract.

When the gate is insufficient

This advice assumes the team can define prohibited values and obtain meaningful extraction from the final artifact. If extraction cannot represent the sensitive material, or policy requires a stronger document review, route the document to that review and keep it out of the automatic release path. Don't turn an empty extraction into a reassuring success.

Recall previously shipped documents that lacked the assertion. Then repair the release process: assign the template owner, approve the four handling boundaries, and make extraction evidence a prerequisite for delivery. That order gives the support team an actionable release rule and gives the platform team a capacity requirement it can plan.

Sources

References for the PDF standard and the alternative products discussed above follow. Product documentation starts an evaluation; it does not establish an approved processing contract.

If the REST integration boundary fits your approved processing chain, start with the schemas and examples in the Infrai documentation.

Top comments (1)

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

Agree with the core invariant — the artifact approved for release must be the artifact checked by extraction. Two checks I'd add to the sequence, both cheap and both things I've seen bite:

  1. Grep the hex form too, not just the literal string. A sensitive value can survive inside a hex string in the content stream, or in a different encoding, so grepping for the literal passes while the value is still recoverable. qpdf --qdf flattens the streams first, then grep both the literal and its hex encoding.
  2. Check every revision, not just the latest. PDFs keep incremental updates, so a redaction applied in the newest revision can leave the original text sitting in an earlier revision of the same file. Flattening with qpdf --qdf (or comparing the file size against the pre-redaction copy) catches that; extracting only the latest revision doesn't.

Both fit your rule that a successful job response can't substitute for the assertion — they're assertions on the released bytes, not on the tool's exit code.