Explore essential security concepts for browser-based games, focusing on XSS vulnerabilities, CSRF prevention, and best practices for safe API usage. This quiz challenges your understanding of common threats and defense mechanisms to keep online gaming platforms secure.
Which of the following scenarios best illustrates a reflected cross-site scripting (XSS) vulnerability in a browser game login page?
Explanation: Reflected XSS occurs when untrusted input from a URL or request is immediately returned and executed by the browser, as seen when a script from a URL parameter runs after form submission. Embedding static script files doesn't involve user input and isn't an XSS risk here. Administrator database access relates to access control, not XSS. Lack of JavaScript validation in password fields does not itself create an XSS vector.
Why can the use of browser cookies for session authentication make a browser game vulnerable to Cross-Site Request Forgery (CSRF) attacks?
Explanation: Cookies are sent automatically with every HTTP request in the browser, so if a player is logged in, a malicious website can initiate requests using those cookies. Encryption by cookies is not a default behavior and does not prevent CSRF on its own. The statement about games not using cookies is incorrect, as many do for sessions. Cookies are sent with both POST and GET requests, not just POST.
What is an important technique to prevent unauthorized in-game purchases through your game's API endpoint?
Explanation: Requiring authentication and validating requests on the server ensures only legitimate players can make purchases and that claims cannot be faked. Allowing requests from any domain increases susceptibility to exploits. Storing tokens only in local storage does not guarantee proper validation. Client-side JavaScript can be manipulated and should not be solely relied upon for security.
How can a browser game prevent XSS attacks when displaying user-generated chat messages?
Explanation: Sanitizing or escaping user input ensures that embedded scripts or markup don't execute in the browser, stopping XSS attacks through chat. Passing chat without modification risks code injection. Only allowing images or videos doesn't address script injection in text or attributes. Trusting users to follow rules is not a security measure and exposes the game to risk.
Which security feature most effectively prevents CSRF in sensitive browser game endpoints, such as changing account email?
Explanation: A CSRF token included in requests and validated by the server ensures that only legitimate actions from the intended user are processed. Disabling cookies breaks session management and is not practical. JavaScript-based checks can often be bypassed by attackers. Allowing HTTP alongside HTTPS weakens transport security, but does not address CSRF directly.