Secure a tiny inventory handler
Does parsing a numeric prefix enforce a whole-input contract?
Entering midway? Revisit Who can read the payroll? for the preceding worked example, or start here and use the explanation below.
Start with a concrete question
Safe inert request inspection: quantities must be whole decimal strings from 1 to 20. No input is executed.
Try the initial inputs, then write a prediction before changing one setting. All calculations run locally on your CPU.
What do you expect?
Before changing a setting: Does parsing a numeric prefix enforce a whole-input contract? Write what you expect and why.
Change one thing. Inspect what happens.
- Try the valid quantity through each boundary.
- Predict what happens to “12 extra” under prefix parsing.
- Inspect markup-like text; distinguish validation from safe display.
- Write pseudocode and test cases for the contract.
Your settingsMechanism
Calculation belowEvidence
Compare outcomes
Compare the current results
Every bar starts at zero and uses the same numeric scale in this chart. The upper bound automatically adjusts to the largest current value (at least 1), so compare the numbers when changing inputs. Units and quantities come from each label; different kinds of quantity are not interchangeable. Displayed values are rounded to at most six significant digits.Follow the calculation
- Submitted inert text: 12. Contract: a whole decimal quantity from 1 to 20.
- No checks; display raw input.
- Fixture handler accepts the request.
- This model compares policies without evaluating or rendering learner text as code.
Validate the complete input at the application boundary and encode output for its context; numeric prefix parsing does not enforce the whole contract.
Repair a sandbox inventory authorization handler
Repair accept(role, quantity). Role 0 is visitor, 1 editor, 2 administrator; only editors and administrators may update stock. Quantity is an already-parsed number and must be an integer from 1 to 20. Run the supplied cases, then add your own. This subset exercise does not parse raw strings or implement a deployed server; the fixture above teaches that separate boundary.
367/8,000 characters. Drafts save locally and are included in backups. Importing or opening a draft never runs it.
Bounded JavaScript subset: variables, primitive arrays, conditions, loops, functions and print. No browser objects, network, imports or eval. Maximum 10,000 operations, 64 array items, call depth 16, strings of 256 characters, 40 output lines / 4,000 output characters and 160 trace frames.
Compare with my earlier draft
function accept(role, quantity) {
return quantity > 0;
}
print("visitor", accept(0, 12), "expected false");
print("editor", accept(1, 12), "expected true");
print("too large", accept(2, 21), "expected false");
print("fraction", accept(1, 2.5), "expected false");
print("zero", accept(1, 0), "expected false");
print("unknown role", accept(9, 12), "expected false");Explain what you changed and why in your observation notes. Text differences do not establish quality.
Inspect an example solution after your attempt
function accept(role, quantity) {
return (role === 1 || role === 2) && quantity >= 1 && quantity <= 20 && quantity % 1 === 0;
}
print("visitor", accept(0, 12), "expected false");
print("editor", accept(1, 12), "expected true");
print("too large", accept(2, 21), "expected false");
print("fraction", accept(1, 2.5), "expected false");
print("zero", accept(1, 0), "expected false");
print("unknown role", accept(9, 12), "expected false");This is one worked example. Test another input and explain its limitations.
Captures keep your inputs, prediction and observation. Results are recalculated from those inputs. Resetting inputs keeps your captures and challenge history.
Explain the mechanism
Secure a tiny inventory handler
Safe inert request inspection: quantities must be whole decimal strings from 1 to 20. No input is executed.
Follow the mechanism
A numeric parser may accept a prefix while ignoring trailing text.
Output encoding prevents text from being interpreted as markup; it is distinct from validating a quantity.
This local simulator never evaluates code and cannot secure a deployed application for you.
Worked example
Submitted inert text: 12. Contract: a whole decimal quantity from 1 to 20.
No checks; display raw input.
Fixture handler accepts the request.
This model compares policies without evaluating or rendering learner text as code.
Calculation
Accept = entire input matches decimal digits AND 1 ≤ numeric quantity ≤ 20.
Try a controlled comparison
Try the valid quantity through each boundary.
Predict what happens to “12 extra” under prefix parsing.
Inspect markup-like text; distinguish validation from safe display.
Write pseudocode and test cases for the contract.
What this does not establish
- All messages, people, documents and outcomes here are original fictional teaching fixtures; results are not measurements of real organizations.
Try a fresh case
A quantity contract accepts integers 1 through 20. For inputs 0, 1, 12, 21, how many should be accepted?
This is a public practice check. Retries support learning; matching a number does not certify independent proficiency.
Take the investigation further
Choose any extension. These are project prompts for you to carry out; they are not automatically assessed.
School investigation
Create a new case with different numbers and explain your decision to a classmate.
College investigation
Implement or analyze a fresh case, document assumptions and compare at least two alternatives.
Workplace investigation
Prepare a decision artifact with evidence, operating constraints, an owner and a follow-up measurement.
Keep the evidence, choose your next step
Completion records your own decision that you have worked through this investigation. Practice checks and independent project evidence are separate.