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:
@@ -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.
|
||||
|
||||
@@ -177,8 +177,33 @@ onMounted(async () => {
|
||||
// An unreachable setting is not proof it is off; let the API decide.
|
||||
disabled.value = false
|
||||
}
|
||||
if (!disabled.value) await probeAdmission()
|
||||
focusEntry()
|
||||
})
|
||||
|
||||
// ASK, rather than guess, whether this screen may use the kiosk.
|
||||
//
|
||||
// The enabled flag is public and says only that the site HAS a kiosk; whether
|
||||
// THIS caller is admitted is decided per request, and the server answers 404
|
||||
// rather than 403 so the route does not advertise itself. Without asking, the
|
||||
// page rendered a keypad and only failed once somebody had typed their SSO -
|
||||
// which reads as broken rather than as not set up.
|
||||
//
|
||||
// The parts kiosk answers the same question by checking whether its browser
|
||||
// holds a token. That test is wrong here: a PC admitted by network carries no
|
||||
// token and is perfectly entitled, so it would warn exactly the callers the
|
||||
// allowlist exists to serve. Hence a real request.
|
||||
//
|
||||
// An empty badge is deliberate. The gate runs before any badge handling, so a
|
||||
// refused caller gets 404 and an admitted one gets the badge validation error -
|
||||
// no lookup, no write, nothing recorded either way.
|
||||
async function probeAdmission () {
|
||||
try {
|
||||
await api.post('/usb/kiosk/session', { badge: '' })
|
||||
} catch (probeError) {
|
||||
if (probeError.response?.status === 404) refused.value = true
|
||||
}
|
||||
}
|
||||
onBeforeUnmount(() => clearTimeout(resetTimer))
|
||||
|
||||
function focusEntry (event) {
|
||||
|
||||
@@ -41,7 +41,13 @@
|
||||
<button type="button" class="btn btn-secondary" @click="generateToken">
|
||||
Generate
|
||||
</button>
|
||||
<button type="button" class="btn btn-secondary" @click="copyLink">
|
||||
Copy setup link
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="linkMessage" class="field-hint">{{ linkMessage }}</p>
|
||||
<input v-if="link" :value="link" type="text" class="form-control"
|
||||
readonly @focus="$event.target.select()" />
|
||||
<p class="field-hint">
|
||||
Provision each screen once by opening
|
||||
<code>/usb-kiosk?token=<this value></code> on it. That browser
|
||||
@@ -97,7 +103,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { settingsApi } from '@/api'
|
||||
import api, { settingsApi } from '@/api'
|
||||
import { withBase } from '@/utils/basePath'
|
||||
import NetworkAllowlistPicker from '@/components/NetworkAllowlistPicker.vue'
|
||||
|
||||
@@ -130,6 +136,35 @@ const saving = ref(false)
|
||||
const message = ref('')
|
||||
const error = ref('')
|
||||
|
||||
// The settings API masks the token, so the field above shows '********' rather
|
||||
// than the value. Copying that provisions a screen with the mask and every
|
||||
// kiosk call answers 404 with nothing to say why. This asks the server for the
|
||||
// real link instead, so the copy step no longer depends on catching the one
|
||||
// moment after Generate when the value is on screen.
|
||||
const link = ref('')
|
||||
const linkMessage = ref('')
|
||||
|
||||
async function copyLink () {
|
||||
linkMessage.value = ''
|
||||
link.value = ''
|
||||
try {
|
||||
const response = await api.get('/usb/kiosk/provisioning-link')
|
||||
const url = window.location.origin + withBase(response.data.data.url)
|
||||
link.value = url
|
||||
try {
|
||||
await navigator.clipboard.writeText(url)
|
||||
linkMessage.value = 'Copied. Open this once on the kiosk screen.'
|
||||
} catch (clipboardError) {
|
||||
// Clipboard access is refused over plain http and in some locked-down
|
||||
// browsers. The link is shown below either way, so this is not a failure.
|
||||
linkMessage.value = 'Copy this and open it once on the kiosk screen.'
|
||||
}
|
||||
} catch (linkError) {
|
||||
linkMessage.value = linkError.response?.data?.data?.error?.message
|
||||
|| 'Could not build the setup link.'
|
||||
}
|
||||
}
|
||||
|
||||
function asBool (value) {
|
||||
return String(value).toLowerCase() === 'true' || value === true || value === 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user