[{"id":"websecuritybeginner-001","courseId":"web-security-beginner","domain":"injection-and-input","topic":"SQL injection from concatenated strings","prompt":"This Java code builds a login query from a typed user name. A user types a name containing a quote mark and SQL keywords. What is the root cause of the risk?","hint":"Think about how the query text is assembled from the user's input.","explain":"A database runs whatever SQL text it receives. If a program pastes user text into that SQL text, the user's characters can become part of the instructions.","source":"https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html","interaction":{"type":"single"},"options":[{"id":"a","text":"The user's text is joined into the SQL string, so the database may read part of it as SQL code.","why":"Concatenation puts data and instructions in one string, so typed characters can change what the query does."},{"id":"b","text":"A length limit on the name field would stop the attack, since short names cannot carry SQL keywords.","whyNot":"Length limits do not separate data from code; a short input can still carry a quote and a keyword."},{"id":"c","text":"Injection only affects INSERT and UPDATE; a SELECT that only reads data cannot be attacked.","whyNot":"Any SQL statement built from user text can be changed, and that includes SELECT."},{"id":"d","text":"The database rejects quote marks, so an attacker only gets an error and no data is exposed.","whyNot":"Attackers use quote marks to end the value early and add their own SQL, so the quote is the attack itself."}],"answer":"a","explanation":"Attackers can use SQL injection on an application if it has dynamic database queries that use string concatenation and user-supplied input.","concept":"Attackers can use SQL injection on an application if it has dynamic database queries that use string concatenation and user-supplied input.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"String query =\n  \"SELECT account_balance FROM user_data\"\n  + \" WHERE user_name = '\" + name + \"'\";","takeaways":["Never build SQL by joining user text into the query string.","Keep SQL code and user data separate in every query."]},{"id":"websecuritybeginner-002","courseId":"web-security-beginner","domain":"injection-and-input","topic":"Parameterized queries","prompt":"The OWASP SQL Injection Prevention Cheat Sheet lists four primary defenses against SQL injection. Put them in the order the cheat sheet numbers them.","hint":"Read the numbers the cheat sheet gives each defense.","explain":"Several defenses can stop SQL injection, but they work in different ways. Some separate user data from SQL code at the query itself, while others check or rewrite the input text.","source":"https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html","interaction":{"type":"sort","items":[{"text":"Use of Prepared Statements (with Parameterized Queries)","why":"Option 1: the cheat sheet's first primary defense, which keeps SQL code and user data apart."},{"text":"Use of Properly Constructed Stored Procedures","why":"Option 2: the second numbered defense, which moves the query into a stored procedure."},{"text":"Allow-list Input Validation","why":"Option 3: the third defense, which checks that input matches what is accepted."},{"text":"STRONGLY DISCOURAGED: Escaping All User Supplied Input","why":"Option 4: the last numbered defense, which the cheat sheet strongly discourages."}]},"options":[],"answer":"o:abcd","explanation":"The cheat sheet lists four primary defenses as numbered options, and it marks escaping all user-supplied input as strongly discouraged.","concept":"The cheat sheet lists four primary defenses as numbered options, and it marks escaping all user-supplied input as strongly discouraged.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Parameterized queries are the first defense the cheat sheet lists.","Escaping user input is the one the cheat sheet strongly discourages."]},{"id":"websecuritybeginner-003","courseId":"web-security-beginner","domain":"injection-and-input","topic":"Allow-list input validation","prompt":"A signup form takes a name, a comment, and a country picked from a drop-down. Which TWO statements about allow-list input validation are correct?","hint":"Consider what an allow-list defines, and what blocking characters can and cannot do.","explain":"Input validation checks data against rules before the application uses it. An allow-list defines what is acceptable, while a denylist tries to name what is bad, and only the first can cover values nobody has listed yet.","source":"https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It defines the values or format the application accepts, and rejects everything outside those rules.","why":"An allow-list states what is accepted, so values outside it are refused without guessing at attack strings."},{"id":"b","text":"Blocking apostrophes in a name does not make a database query safe on its own.","why":"The cheat sheet says blocking apostrophes rejects legitimate names without making a database query safe."},{"id":"c","text":"It is safer to list known attack strings and reject any value that contains one.","whyNot":"That is a denylist; the cheat sheet says not to try to recognize every malicious string."},{"id":"d","text":"A country picked from a drop-down needs no server check, because the menu only offers allowed values.","whyNot":"The cheat sheet says to check exact membership on the server, including values from drop-down menus."},{"id":"e","text":"A free-text comment must be limited to letters and digits to pass allow-list validation.","whyNot":"For free-form comments, an allow-list can permit broad Unicode text while limiting length; letters and digits are not required."},{"id":"f","text":"Stripping apostrophes from a name is how to stop SQL injection in that field.","whyNot":"Removing apostrophes rejects valid names and does not parameterize the query, so injection can remain."}],"answer":"ab","explanation":"Define what the application accepts and reject values outside those rules. Blocking apostrophes, for example, rejects legitimate names without making a database query safe.","concept":"Define what the application accepts and reject values outside those rules. Blocking apostrophes, for example, rejects legitimate names without making a database query safe.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["An allow-list states what is accepted; blocking bad characters is not a defense on its own."]},{"id":"websecuritybeginner-004","courseId":"web-security-beginner","domain":"injection-and-input","topic":"Server-side validation over client checks","prompt":"A signup form checks the age field with JavaScript in the browser. Because the browser already checked it, the server can skip checking the age field.","hint":"Think about who controls the browser and what a user can send instead.","explain":"Checks that run in the browser give fast feedback, but the user controls that environment. The server must decide what it accepts from any request.","source":"https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Client-side checks can be bypassed, so the server must validate the same fields itself."},{"id":"b","text":"False","why":"The cheat sheet says to validate on the server even when the browser checks the same fields."}],"answer":"b","explanation":"Validate on the server even when the browser checks the same fields. Client-side validation is bypassable; use it for immediate feedback.","concept":"Validate on the server even when the browser checks the same fields. Client-side validation is bypassable; use it for immediate feedback.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Browser checks help users; only server-side checks protect the application."]},{"id":"websecuritybeginner-005","courseId":"web-security-beginner","domain":"injection-and-input","topic":"Avoiding OS command calls","prompt":"A PHP app must create a folder whose name comes from user input. Which approach does the OWASP OS Command Injection Defense Cheat Sheet recommend first?","hint":"Ask whether a shell has to be involved at all.","explain":"A shell reads a command as text, so characters in user input can add new commands or arguments. Some tasks have a built-in function that does not hand text to a shell.","source":"https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Call the built-in library function for creating directories, such as mkdir(), instead of a shell command.","why":"The primary defense is to avoid OS commands, and library functions cannot be manipulated into other tasks."},{"id":"b","text":"Run system('mkdir ' . $name) after passing the name through escapeshellarg().","whyNot":"Escaping helps, but the cheat sheet treats it as a secondary option, and an attacker can still pass an extra argument."},{"id":"c","text":"Run system('mkdir ' . $name) only after checking that the name has no spaces.","whyNot":"Filtering out spaces is a partial check; the command still goes through the OS instead of being avoided."},{"id":"d","text":"Run the command through the shell, since the shell checks the name before it runs the command.","whyNot":"The cheat sheet says system() passes its arguments to the shell to be parsed, which is the risk, not a check."}],"answer":"a","explanation":"The primary defense is to avoid calling OS commands directly. Built-in library functions are a very good alternative to OS Commands.","concept":"The primary defense is to avoid calling OS commands directly. Built-in library functions are a very good alternative to OS Commands.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Prefer a built-in library function over a shell command."]}]