4 lines
1.3 KiB
HTML
4 lines
1.3 KiB
HTML
<!doctype html><html lang="en"><meta charset="utf-8"><title>Validate before crossing a boundary</title><h1>Validate before crossing a boundary</h1><p>15-minute session: read for 3 minutes, trace for 3, experiment for 7, and complete the check for 2. Spend longer whenever you need.</p><p>Treat external values as untrusted. Define valid type, size, range, and structure before use. Reject an invalid value with a clear error instead of silently turning it into a different request. Test both endpoints and the values immediately outside them. A validated value still needs authorization for the requested action.</p><p><strong>Practice and evidence:</strong> Predict the example or draw its state transitions. Change one assumption, test the boundary, and record the actual result. Explain what this small model does not establish about a production system.</p><pre><code class="language-python">def valid_score(value):
|
|
return type(value) is int and 0<=value<=100
|
|
print([valid_score(x) for x in [-1,0,100,101,True]])
|
|
</code></pre><p><strong>Expected result:</strong> <code>[False, True, True, False, False]</code></p><h3>Practice and evidence</h3><p>Keep three notes: your prediction, the actual result, and why they match or differ. The completion check grades understanding; the practice task builds skill.</p></html> |