Exam PT0-002 All QuestionsBrowse all questions from this exam
Question 265

During a code review assessment, a penetration tester finds the following vulnerable code inside one of the web application files:

<% String id = request.getParameter("id"); %>

Employee ID: <%= id %>

Which of the following is the BEST remediation to prevent a vulnerability from being exploited, based on this code?

    Correct Answer: C

    The code snippet shows that data from the user input is directly embedded into the HTML output. This poses a Cross-Site Scripting (XSS) risk because an attacker could inject malicious scripts through the user input. Output encoding is the best method to prevent XSS by converting special characters in the user input to their corresponding HTML entities, ensuring the input is treated as text and not executable code.

Discussion
ACMaverickOption: C

This code is vulnerable to injection attacks, where an attacker can manipulate the id parameter to execute arbitrary code on the server or access sensitive data. The best remediation to prevent this vulnerability from being exploited is C. Output encoding. Output encoding involves converting special characters to their corresponding HTML entities, which prevents them from being interpreted as code by the browser. In this case, the id parameter should be encoded before it is displayed on the web page. Option A, parameterized queries, is a remediation technique used to prevent SQL injection attacks, not injection attacks in general. Option B, patch application, is not a remediation technique for injection attacks. It involves applying software patches to fix known vulnerabilities in software. Option D, HTML sanitization, involves removing or modifying potentially malicious code from user input before it is processed by the server. While this technique can be effective in preventing injection attacks, it is not as effective as output encoding . Therefore, option C is the best remediation to prevent a vulnerability from being exploited.

LiveLaughToasterBathOption: C

From LinkedIn: Output encoding is the process of transforming data into a safe format that does not interfere with the intended functionality or appearance of the web page. In this article, we will discuss the best practices for output encoding to prevent XSS attacks.Mar 21, 2023

Etc_Shadow28000Option: C

C. Output encoding Explanation: The vulnerable code is using the id parameter directly in the output without any form of sanitization or encoding, which can lead to cross-site scripting (XSS) attacks. By encoding the output, you ensure that any potentially malicious input is rendered harmless in the browser. A. Parameterized queries: This is a defense against SQL injection attacks. Since the provided code snippet does not involve any database operations, parameterized queries are not relevant here. B. Patch application: While keeping software up-to-date is important, it is not a specific remediation for the kind of vulnerability present in the provided code. D. HTML sanitization: This is also a valid approach to mitigate XSS by sanitizing input. However, in this specific context, output encoding is typically a more straightforward and reliable way to prevent XSS by ensuring that any user-provided data is safely rendered.

deedenOption: A

I vote A here because when the web application process this, I'm thinking "id" is processed through some kind of database in the backend and this query can lead to SQL injection. Output encoding usually prevents symbols such as <> to be parsed as part of the URL, isn't it?

deeden

I take it back, I agree on option C.

041ba31Option: C

In the given code snippet, the value of the "id" parameter obtained from the request is directly printed into the HTML response without any validation or sanitization. This leaves the application vulnerable to Cross-Site Scripting (XSS) attacks. Output encoding, specifically encoding special characters before outputting them into HTML, helps prevent XSS vulnerabilities by ensuring that user-supplied data is treated as data and not as executable code.