Skip to content

fix(printing): prevent DOM sanitizer from stripping style tags in thermal receipt templates #185

Closed

Description

@khaira777

Summary

The DOM sanitizer in PrinterService.ts strips <style> elements from receipt HTML templates, breaking custom layout and CSS styling in thermal receipts.

Root Cause

In frontend/src/lib/printer/PrinterService.ts, line 243 executes:
parsed.querySelectorAll('script, style, link, meta, base, iframe, object, embed, form').forEach((node) => node.remove());
Including style in the selector query removes valid inline CSS <style> blocks contained in thermal receipt templates.

Why It Matters

Custom receipt thermal formatting (font sizes, table column alignment, border rules) gets stripped before rendering, causing receipts to lose formatting when printed.

Expected Behavior

Executable scripts and dangerous remote resources are stripped, but embedded <style> elements needed for receipt formatting are preserved.

Actual Behavior

<style> elements are purged alongside <script> tags.

Affected Files

  • frontend/src/lib/printer/PrinterService.ts

Suggested Implementation Direction

Remove style from the querySelectorAll selector array while retaining script, iframe, and form element purging.

Activity

  1. added theissue type on Jul 29, 2026
  2. removed theissue type on Jul 29, 2026
  3. itsbkm commented on Jul 29, 2026

    @itsbkm
    Contributor

    Fixed in a0b41f1: removed 'style' from the sanitizer's querySelectorAll removal list in PrinterService.ts — script/iframe/form/etc. stripping is unchanged, but <style> blocks needed for receipt formatting are now preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions