Trust boundaries and data flow
Quick answer
A trust boundary separates inputs whose claims have not been established from code that acts on validated data. Treat form values, network responses, stored JSON and messages as untrusted until the relevant checks succeed.
How it works
Identify the source, validation step, and sink (the operation that consumes the data). Different sinks have different requirements: a quantity must be an integer within bounds, a text node needs text, and navigation needs a destination policy. A successful shape check is not permission to modify another account. A server must determine identity and authorize its own operations independently of client decisions.
Local examples
Run in Node.js v22.16.0 as a CommonJS script. Actual ByteMind editor support is unverified.
(async () => {const qty=x=>Number.isInteger(x)&&x>=0&&x<=20?x:null;console.log(qty(0),qty("3"),qty(21));})()Expected console output:
0 null nullThe domain accepts zero but not a numeric string or an out-of-range number.
Run in Node.js v22.16.0 as a CommonJS script. Actual ByteMind editor support is unverified.
(async () => {const allowed=(actor,record)=>actor.id===record.owner;console.log(allowed({id:"A"},{owner:"A"}),allowed({id:"B"},{owner:"A"}));})()Expected console output:
true falseOwnership matters independently of record shape.
Common mistakes
Do not treat a value as trusted just because it came from your own storage or because the browser validated a form.
Practice
Draw the flow from a quantity form to a server operation, identifying shape validation, authorization and safe display as separate checks.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Trust boundaries and data flow — Knowledge Check
Apply the concept and reason about local example output.
What should establish permission to update an account record?
Which location is a trust boundary for a saved JSON preference?
Why define a sink before choosing a protection?
What is the exact console output in Trust boundaries and data flow example 1?
(async () => {const qty=x=>Number.isInteger(x)&&x>=0&&x<=20?x:null;console.log(qty(0),qty("3"),qty(21));})()What is the exact console output in Trust boundaries and data flow example 2?
(async () => {const allowed=(actor,record)=>actor.id===record.owner;console.log(allowed({id:"A"},{owner:"A"}),allowed({id:"B"},{owner:"A"}));})()