Back to the full dot-point answer
NSWSoftware EngineeringQuick questions
Module 1: Secure Software Architecture
Quick questions on Input validation and sanitisation explained: HSC Software Engineering Module 1
12short Q&A pairs drawn directly from our worked dot-point answer. For full context and worked exam questions, read the parent dot-point page.
What is input validation?Show answer
Check that incoming data matches an expected format before processing it. Two approaches:
What is sanitisation?Show answer
Transform input to make it safe for downstream use. Removes or escapes unwanted characters but does not reject the request.
What is output encoding?Show answer
Transform data at the boundary where it is written to a target context. The encoding depends on the context:
What is the big example?Show answer
Submitting ' OR '1'='1 as the password turns the query into:
What is defence in depth?Show answer
Real systems combine all three:
What is validation?Show answer
reject empty comments, comments over 5000 characters, comments containing null bytes. Allow normal Unicode text.
What is sQL boundary?Show answer
insert the comment with a parameterised query. No need to escape SQL metacharacters - the driver handles it.
What is hTML output boundary?Show answer
HTML-encode the comment text when rendering. Convert less-than to ampersand-lt-semicolon, greater-than to ampersand-gt-semicolon, ampersand itself to ampersand-amp-semicolon, and the two quote characters to their numeric or named entities. Prevents stored XSS attacks where a malicious commenter injects script tags.
What is validating only on the client?Show answer
Browser validation is a UX feature, not a security control. An attacker hits the API directly.
What is using a deny-list of "dangerous characters"?Show answer
Attackers find encodings you missed. Allow-list what you want; reject everything else.
What is encoding once at storage time?Show answer
You may need to render data in HTML, in a JSON API response, and in a CSV export. Encode at the output boundary, not at storage, so the same stored value can be rendered safely in multiple contexts.
What is forgetting the database is not the only injection target?Show answer
Command injection, LDAP injection, NoSQL injection, and template injection all follow the same pattern. The defence is the same: parameterise or context-encode at the output boundary. :::