Say when a kiosk screen is not set up, and hand out the setup link

Two failures from the same root: an administrator cannot see the kiosk token,
and a screen that was provisioned wrongly does not say so.

The settings API masks every key whose name contains 'token', so the settings
page shows '********'. The real value is visible for one moment - after
Generate, before Save - and an administrator who copies the field at any other
time provisions a screen with the literal mask. The kiosk then answers 404,
exactly as it answers a caller it has never heard of, because the route
deliberately does not advertise itself. Nothing anywhere says what went wrong.

- Each kiosk gains a permission-gated provisioning-link route that returns the
  real setup URL, token included, to somebody who already holds settings.edit.
  The mask stays: a token has no business in an ordinary settings list. The
  copy step just stops depending on catching the one moment it is on screen.
  Revealing it writes an audit row, since that is when the value left the
  database. Both settings pages get a "Copy setup link" button, which falls
  back to showing the link when the clipboard is refused - it is, over plain
  http and in locked-down browsers.
- The USB kiosk asks the server on load whether this screen may be used, and
  says plainly when it may not. It rendered a keypad and only failed once
  somebody had typed their SSO, which reads as broken rather than as not set
  up. It cannot guess: the enabled flag is public and only says the site has a
  kiosk, and a caller admitted by network holds no token to look for, so the
  parts kiosk's localStorage check would warn exactly the callers the allowlist
  exists to serve. The probe is a badge-less session request - the gate runs
  before any badge handling, so refused is 404 and admitted is the validation
  error, with no lookup and nothing recorded. A test pins that ordering,
  because reordering it would start telling admitted screens they are not set
  up.

Verified in a browser, not only in tests: provisioning with the mask lands on
the refused screen, a correct token gets the drive list and survives a plain
revisit, and a tokenless caller inside the allowlist gets straight in.
This commit is contained in:
cproudlock
2026-09-16 15:26:44 -04:00
parent da91a29155
commit 0f56653345
6 changed files with 217 additions and 3 deletions

View File

@@ -39,7 +39,7 @@ from shopdb.api import (
get_pagination_params,
require_permission,
)
from shopdb.api import Setting, request_ip_allowlisted
from shopdb.api import Setting, request_ip_allowlisted, audit_log, db
from . import selfhosted
@@ -815,6 +815,40 @@ def _kiosk_badge(data):
return badge, None
@usb_bp.route('/kiosk/provisioning-link', methods=['GET'])
@require_permission('settings.edit')
def kiosk_provisioning_link():
"""The URL that provisions a screen, token included, for an administrator.
WHY THIS EXISTS. The settings API masks every key whose name contains
'token', so the settings page shows the kiosk token as '********'. The real
value is visible for exactly one moment - after Generate, before Save - and
an administrator who copies the field at any other time provisions a screen
with the literal string '********'. Nothing says so: the kiosk answers 404
the same way it answers a caller it has never heard of, because the route
deliberately does not advertise itself. That has cost real time.
So the copy step stops depending on catching that moment. The mask stays -
it is right that a token does not travel in an ordinary settings list - and
this named, permission-gated route hands the value to somebody who is
already allowed to set it.
Returns a relative URL. The caller's own origin is the right base for a
screen being provisioned from that same browser, and the server has no
reliable idea what hostname the operator reached it by.
"""
token = (Setting.get('usb_kiosk_token') or '').strip()
if not token:
return error_response(ErrorCodes.VALIDATION_ERROR,
'No kiosk token set. Generate one first.')
# Revealing a credential is worth a line in the audit log: it is the moment
# the value left the database, and the trail should say who asked.
audit_log('viewed', 'Setting', entityname='usb_kiosk_token',
details='kiosk provisioning link')
db.session.commit()
return success_response({'url': '/usb-kiosk?token=' + token})
@usb_bp.route('/kiosk/device/<device_id>', methods=['GET'])
def kiosk_device(device_id):
"""What the kiosk shows after a device is scanned.