Skip to content

fix: prevent direct client invocation of KOT generation for arbitrary POS I - #231

Draft
esafwan wants to merge 1 commit into
developfrom
task/SweepSecurity-SEC-18-impl-1
Draft

fix: prevent direct client invocation of KOT generation for arbitrary POS I#231
esafwan wants to merge 1 commit into
developfrom
task/SweepSecurity-SEC-18-impl-1

Conversation

@esafwan

@esafwan esafwan commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What it does / Summary

Hardens KOT generation by making kot_execute server-side only, introducing a secure whitelisted endpoint kot_execute_for_invoice, and updating the POS Invoice JS form script (ury_pos_kot.js).

What it solves / Motivation

  • Resolves security finding SEC-18 by preventing malicious or unauthorized callers from executing KOT creation/cancellation on arbitrary POS Invoices with arbitrary client-supplied item arrays.
  • Guarantees KOT items are derived directly from the saved POS Invoice document in the database rather than unvalidated client inputs.

Key Technical Changes

  • Backend API (ury/ury/api/ury_kot_generate.py):
    • Removed @frappe.whitelist() decorator from kot_execute, restricting it to server-side callers (e.g., ury_order.sync_order).
    • Added _get_user_branches and _validate_kot_access to enforce POS Invoice write permission and branch assignment via tabURY User.
    • Introduced kot_execute_for_invoice which validates access, verifies draft docstatus (docstatus == 0), and extracts current item data directly from the saved pos_invoice.items.
  • Frontend Form Script (ury/public/js/ury_pos_kot.js):
    • Updated form call to invoke kot_execute_for_invoice.
    • Removed client-side payload assembly for current items, trusting backend item resolution.

Remove the unauthenticated-shape whitelisted kot_execute entry point that
let any authenticated user create/cancel KOTs for an arbitrary POS
Invoice ID with client-supplied items.

- kot_execute is no longer whitelisted; it remains the internal
  implementation used by the server-side URY order sync flow.
- New whitelisted kot_execute_for_invoice validates POS Invoice write
  permission, branch assignment (URY User), and draft docstatus, and
  derives current items from the saved invoice instead of trusting
  client input.
- POS Invoice form script updated to call the validated endpoint.
@esafwan esafwan changed the title Prevent direct client invocation of KOT generation for arbitrary POS I fix: prevent direct client invocation of KOT generation for arbitrary POS I Jul 21, 2026
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.

1 participant