Skip to content

fix: harden JWT exp, 58mm print, and printer IPs - #1521

Merged
khaira777 merged 3 commits into
mainfrom
fm/flocafe-release-audit-fixes
Nov 8, 2026
Merged

khaira777 merged 3 commits into
mainfrom
fm/flocafe-release-audit-fixes

Conversation

@khaira777

@khaira777 khaira777 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1512

Intent

Verify and fix the three findings from the post-6949d359 release audit on main with regression tests and final verification for next-release readiness:

  1. [P2] Keep session expiry tied to wall-clock time (main/routes/auth.ts:301 and token issuers using nextTokenIatSeconds()): After a clock correction, the logical monotonic iat from nextTokenIatSeconds() can remain ahead of wall-clock time, and passing expiresIn to jwt.sign computes exp relative to that future iat instead of actual wall-clock time (Date.now()). A 48-hour clock correction produced a fresh "24-hour" session lasting 72 hours and still authenticating after 25 hours. Calculate expiry from actual wall-clock time across the token issuers while preserving tokens_valid_after revocation ordering.
  2. [P2] Prevent overflow for normal and large 58mm receipts (frontend/src/lib/printer/web-print.ts:613): In getPaperStyles('thermal58', textSize), the bounded flex/wrapping layout rules apply only to extra_large. With the real HTML generator, "Breakfast", quantity 2, at ₹125 fitted at baseline, but the candidate's 219px container overflowed to 230px at normal size and 260px at large size, risking clipping or unwanted print scaling. Apply a bounded layout to every 58mm text size preset (normal, large, and extra_large) while preserving complete financial values, and test each preset.
  3. Pre-existing hardening gap in printer target validation (main/printers/thermal.ts:5063): validateNetworkPrinterTarget accepts shorthand/non-canonical numeric IPv4 aliases such as 127.1 (for which net.isIP returns 0) that OS resolvers map to blocked local/loopback endpoints. Harden validateNetworkPrinterTarget so shorthand or non-canonical numeric IPv4 aliases cannot bypass local-port, loopback, unspecified/broadcast, or metadata target checks.

What Changed

  • Compute JWT exp claims explicitly from wall-clock Date.now() across API (main/routes/auth.ts), KDS (main/kds-server.ts), and Server App (main/server-app.ts) token issuers while retaining monotonic nextTokenIatSeconds() iat values for revocation ordering.
  • Apply the bounded flex-wrap item table layout across all thermal58 receipt text size presets (normal, large, and extra_large) in getPaperStyles (frontend/src/lib/printer/web-print.ts) so 58mm HTML receipts do not overflow horizontally.
  • Normalize non-canonical IPv4 host candidates via URL hostname parsing in validateNetworkPrinterTarget (main/printers/thermal.ts) so shorthand, octal, hexadecimal, and integer IPv4 forms cannot bypass loopback, local-port, broadcast/unspecified, or cloud metadata target checks.

Risk Assessment

✅ Low: The changes are minimal, targeted fixes for wall-clock JWT expiry across all seven issuers, unconditional 58mm receipt row wrapping across all text sizes, and non-canonical IPv4 alias normalization in network printer target validation, with comprehensive behavioral regression tests and updated architecture documentation.

Testing

Exercised the JWT lifecycle suite across the Main API, Server App, and KDS HTTP servers, the printer API and dispatch target-validation suite, and the Chromium browser receipt suite with visual screenshots of the 58mm 'Breakfast' x2 at ₹125 receipt across normal, large, and extra_large text sizes; all scenarios passed with zero overflow and full enforcement of wall-clock session expiry and shorthand IPv4 printer target blocking.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
After a +48h forward clock jump and correction back to wall-clock time, all 7 token issuers (/api/auth/setup/initialize, /api/auth/login, /api/auth/pin-login, /api/auth/tenants/select, /api/auth/refre… ✅ pass live npx tsx tests/jwt-logout-lifecycle.test.ts
A 58mm browser thermal receipt for 'Breakfast' (qty 2 at ₹125.00, total ₹250.00) renders in real headless Chromium across normal, large, and extra_large text-size presets with bounded flex-wrapped ite… ✅ pass live ~/.no-mistakes/evidence/01M6YD4PJNQGYATRN5T8E6XW6F/thermal58_breakfast_normal.png, ~/.no-mistakes/evidence/01M6YD4PJNQGYATRN5T8E6XW6F/thermal58_breakfast_large.…
Configuring a network printer via POST /api/printers or dispatching via printViaNetwork rejects shorthand, octal, hexadecimal, and single-integer IPv4 aliases for loopback FloCafe ports (127.1:3001, 1… ✅ pass live npx tsx tests/printer-api.test.ts

58mm receipt ('Breakfast' x2 at ₹125) rendered in Chromium at 'normal' text size (219px container, zero horizontal overflow)
58mm receipt ('Breakfast' x2 at ₹125) rendered in Chromium at 'large' text size (219px container, zero horizontal overflow)
58mm receipt ('Breakfast' x2 at ₹125) rendered in Chromium at 'extra_large' text size (219px container, zero horizontal overflow)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
After a +48h forward clock jump and correction back to wall-clock time, all 7 token issuers (/api/auth/setup/initialize, /api/auth/login, /api/auth/pin-login, /api/auth/tenants/select, /api/auth/refre… ✅ pass live npx tsx tests/jwt-logout-lifecycle.test.ts
A 58mm browser thermal receipt for 'Breakfast' (qty 2 at ₹125.00, total ₹250.00) renders in real headless Chromium across normal, large, and extra_large text-size presets with bounded flex-wrapped ite… ✅ pass live ~/.no-mistakes/evidence/01M6YD4PJNQGYATRN5T8E6XW6F/thermal58_breakfast_normal.png, ~/.no-mistakes/evidence/01M6YD4PJNQGYATRN5T8E6XW6F/thermal58_breakfast_large.…
Configuring a network printer via POST /api/printers or dispatching via printViaNetwork rejects shorthand, octal, hexadecimal, and single-integer IPv4 aliases for loopback FloCafe ports (127.1:3001, 1… ✅ pass live npx tsx tests/printer-api.test.ts
  • npx tsx tests/jwt-logout-lifecycle.test.ts
  • REQUIRE_VISUAL_EVIDENCE=1 EVIDENCE_DIR=~/.no-mistakes/evidence/01M6YD4PJNQGYATRN5T8E6XW6F npx tsx tests/browser-receipts.test.ts
  • npx tsx tests/printer-api.test.ts
  • Playwright Chromium rendering and screenshot capture of 58mm 'Breakfast' x2 at ₹125 receipts across normal, large, and extra_large presets
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Compute JWT exp from wall-clock Date.now() across all 7 token issuers while preserving monotonic sub-second iat for revocation ordering, apply bounded flex-wrap item rows to all 58mm browser receipt text sizes (normal, large, extra_large), and canonicalize shorthand/non-canonical IPv4 printer hosts via WHATWG URL parsing in validateNetworkPrinterTarget.

Fixes #1512
@qodo-code-review

Copy link
Copy Markdown

ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix JWT expiry, 58mm receipt overflow, and IPv4 printer validation

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Tie JWT expiry to wall-clock time without changing monotonic issuance timestamps used for
 revocation.
• Bound 58mm receipt rows at every text size without truncating financial values.
• Normalize non-canonical IPv4 printer targets before applying address restrictions, with regression
 coverage for all three fixes.
Diagram

graph TD
  F["Release fixes"] --> A["JWT issuers"] --> B["Wall-clock expiry"]
  F --> C["58mm styles"] --> D["Bounded rows"]
  F --> E["Target validator"] --> G["Canonical IPv4 checks"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Centralize JWT issuance
  • ➕ Keeps expiry and issuance-time policy consistent across API, KDS, and Server App.
  • ➖ Broadens this corrective PR into a refactor of issuers with different claims and remember-me behavior.

Recommendation: Keep the focused fixes for this release: explicit wall-clock expiry, shared 58mm layout rules, and URL-based IPv4 normalization address the observed failures without replacing existing issuance or validation paths. A shared JWT issuer is worth considering separately if future changes continue to duplicate expiry policy.

Files changed (10) +325 / -42

Bug fix (5) +38 / -31
web-print.tsApply bounded 58mm item layout to every preset +9/-15

Apply bounded 58mm item layout to every preset

• Makes the existing flex-wrap and word-wrapping rules unconditional for thermal58, covering normal, large, and extra_large receipts.

frontend/src/lib/printer/web-print.ts

kds-server.tsSet KDS token expiry from wall-clock time +1/-1

Set KDS token expiry from wall-clock time

• Adds an explicit 24-hour exp claim while preserving the monotonic iat used by token revocation.

main/kds-server.ts

thermal.tsNormalize numeric IPv4 printer host aliases +10/-0

Normalize numeric IPv4 printer host aliases

• Uses URL hostname parsing to recognize non-canonical IPv4 forms before applying existing metadata, unspecified, broadcast, and local-port restrictions.

main/printers/thermal.ts

auth.tsUse wall-clock expiry throughout API token issuance +17/-14

Use wall-clock expiry throughout API token issuance

• Replaces expiresIn signing options with explicit exp claims for login, PIN login, tenant selection, refresh, and setup. Keeps remember-me durations and response expiry values aligned with the token TTLs.

main/routes/auth.ts

server-app.tsSet Server App token expiry from wall-clock time +1/-1

Set Server App token expiry from wall-clock time

• Adds an explicit 24-hour or 10-day exp claim based on remember_me without changing the monotonic iat.

main/server-app.ts

Tests (3) +280 / -7
browser-receipts.test.tsCover 58mm receipt width at all text sizes +77/-7

Cover 58mm receipt width at all text sizes

• Checks that every preset receives wrapping rules. A Chromium regression case verifies that a representative INR bill stays within its container and retains its item and financial text.

tests/browser-receipts.test.ts

jwt-logout-lifecycle.test.tsCover token expiry after a clock correction +195/-0

Cover token expiry after a clock correction

• Exercises API, KDS, and Server App issuers after a 48-hour clock jump and correction. Checks wall-clock exp values, preserved monotonic iat values, and rejection of 24-hour tokens after 25 hours.

tests/jwt-logout-lifecycle.test.ts

printer-api.test.tsCover non-canonical IPv4 printer targets +8/-0

Cover non-canonical IPv4 printer targets

• Adds blocked-target cases for shorthand, integer, octal, and hexadecimal IPv4 aliases that resolve to restricted destinations.

tests/printer-api.test.ts

Documentation (2) +7 / -4
authentication-and-authorization.mdDocument wall-clock JWT expiry +3/-1

Document wall-clock JWT expiry

• Clarifies that tokens retain monotonic iat values for revocation while exp is calculated from wall-clock time.

docs/architecture/authentication-and-authorization.md

printing.mdDocument printer validation and 58mm wrapping +4/-3

Document printer validation and 58mm wrapping

• Describes restrictions on non-canonical IPv4 printer targets and item-row wrapping across 58mm text sizes.

docs/architecture/printing.md

@qodo-code-review

qodo-code-review Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Receipt rendering checks can be skipped 🐞 Bug ☼ Reliability
Description
The new three-preset rendering loop sits inside a Playwright try whose catch only logs a warning
unless REQUIRE_VISUAL_EVIDENCE is set. When Chromium cannot launch or a preceding screenshot step
fails, the test run can succeed without executing any of the new rendered-overflow assertions.
Code

tests/browser-receipts.test.ts[R2107-2113]

+    for (const preset of ['normal', 'large', 'extra_large'] as const) {
+      const presetHtml = generateBillHtml(breakfastInrBill, inrTenant, {
+        language: 'en',
+        paperSize: 'thermal58',
+        textSize: preset,
+      });
+      await page.setContent(presetHtml, { waitUntil: 'load' });
Relevance

●●● Strong

Same try/catch pattern gated by REQUIRE_VISUAL_EVIDENCE was accepted as a fix in PR #612 when the
catch swallowed real assertion failures.

PR-#612
PR-#427

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The newly added behavioral assertions run after Chromium launch and the screenshot loop in the same
try. The surrounding catch suppresses those failures by default, while the release-regressions
script invokes this test without setting the environment variable that would make the catch rethrow.

tests/browser-receipts.test.ts[1996-2017]
tests/browser-receipts.test.ts[2107-2128]
tests/browser-receipts.test.ts[2130-2135]
package.json[262-273]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new rendered receipt assertions can be bypassed when the optional Playwright block catches a browser or screenshot failure.

## Fix Focus Areas
- tests/browser-receipts.test.ts[2107-2128]
- tests/browser-receipts.test.ts[2131-2134]

## Recommended Fix
Run the three-preset regression in a required browser-test path, or mark its absence as a test failure in the test configuration that is expected to verify this fix. Keep optional screenshot capture separate from the required assertions.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


2. Receipt headings no longer align with prices 🐞 Bug ≡ Correctness
Description
The new 58 mm flex rule sizes each quantity, rate and amount cell with flex: 1 1 auto,
independently for the header and every item row. On normal and large receipts, headings and values
with different text widths receive different column boundaries, making the numeric values harder to
associate with their headings.
Code

frontend/src/lib/printer/web-print.ts[636]

+        .items-table th:not(:first-child), .items-table td:not(:first-child) { flex: 1 1 auto; min-width: 0; }
Relevance

●● Moderate

Subjective 58mm layout concern; the PR intentionally applies this layout to all presets. Closest
precedent PR #1493 (accepted) concerned 58mm column fit, but not this alignment.

PR-#1493
PR-#676

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The generated header has item, quantity, rate and amount cells, while each item row has a name
followed by quantity, unit price and amount. The changed CSS makes each row a separate flex
container and sizes its three numeric cells from their own content, rather than using shared table
columns.

frontend/src/lib/printer/web-print.ts[383-410]
frontend/src/lib/printer/web-print.ts[632-637]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new 58 mm flex layout independently sizes header and item-row numeric cells, so their columns do not align.

## Fix Focus Areas
- frontend/src/lib/printer/web-print.ts[632-637]

## Recommended Fix
Keep the full-width item-name line, but assign the three numeric cells consistent column tracks or widths in both the header and each item row. Preserve wrapping within those tracks and verify alignment across all three text sizes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


3. Wider receipts can pass the overflow test 🐞 Bug ⚙ Maintainability
Description
The new Chromium assertion compares scrollWidth only with the receipt's measured clientWidth,
without asserting that the client width remains 58 mm. If a layout change expands the container to
fit its contents, all three preset checks can pass even though the receipt no longer fits the
intended paper width.
Code

tests/browser-receipts.test.ts[R2124-2125]

+        metrics.clientWidth > 0 &&
+          metrics.scrollWidth <= metrics.clientWidth &&
Relevance

●● Moderate

Test-strengthening suggestions are often accepted, but no direct precedent for asserting a fixed
58mm client width; team stance is unclear.

PR-#676
PR-#1376

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new test claims to check a 219 px container, but its only width requirements are a positive
client width and a scroll width no greater than that same client width. The production stylesheet
supplies the 58 mm width that the regression test needs to guard.

tests/browser-receipts.test.ts[2066-2067]
tests/browser-receipts.test.ts[2114-2128]
frontend/src/lib/printer/web-print.ts[614-616]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The browser regression check permits a widened receipt container to hide horizontal overflow.

## Fix Focus Areas
- tests/browser-receipts.test.ts[2114-2128]

## Recommended Fix
Measure the receipt and its print-width reference in Chromium, assert that the container remains within the intended 58 mm width, and retain the scroll-width and financial-value checks for each preset.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #39
✅ Compliance rules (platform): 5 rules
✅ Cross-repo context — repo relationships
✅ REVIEW.md
Review mode: Auto: ⚖️ Balanced: Touches JWT auth expiry, printer target SSRF checks, and receipt layout; security-sensitive.

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread frontend/src/lib/printer/web-print.ts Resolved
Comment thread tests/browser-receipts.test.ts Resolved
Comment thread tests/browser-receipts.test.ts Resolved
@khaira777 khaira777 changed the title fix: bind JWT expiry to wall-clock time, bound 58mm receipt layout, and normalize IPv4 printer targets fix: harden JWT exp, 58mm print, and printer IPs Nov 8, 2026
@khaira777
khaira777 merged commit 8791326 into main Nov 8, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-release-audit-fixes branch November 8, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: wall-clock JWT expiry, 58mm receipt layout, and printer IP alias guard

1 participant