nerdexam
CompTIA

SY0-301 · Question #356

The BEST methods for a web developer to prevent the website application code from being vulnerable to cross-site request forgery (XSRF) is to: (Select TWO).

The correct answer is C. Validate and filter input on the server side and client side. E. Restrict and sanitize use of special characters in input and URLs. Cross-site request forgery is mitigated by ensuring that requests contain validated, sanitized tokens or parameters that a forged request cannot predict or replicate. Server-side and client-side input validation combined with special-character sanitization are standard defenses.

Threats, vulnerabilities, and mitigations

Question

The BEST methods for a web developer to prevent the website application code from being vulnerable to cross-site request forgery (XSRF) is to: (Select TWO).

Options

  • APermit redirection to Internet-facing web URLs.
  • BEnsure all HTML tags are enclosed in angle brackets, e.g., "<" and ">".
  • CValidate and filter input on the server side and client side.
  • DUse a web proxy to pass website requests between the user and the application.
  • ERestrict and sanitize use of special characters in input and URLs.

How the community answered

(25 responses)
  • A
    8% (2)
  • B
    4% (1)
  • C
    84% (21)
  • D
    4% (1)

Why each option

Cross-site request forgery is mitigated by ensuring that requests contain validated, sanitized tokens or parameters that a forged request cannot predict or replicate. Server-side and client-side input validation combined with special-character sanitization are standard defenses.

APermit redirection to Internet-facing web URLs.

Permitting redirection to internet-facing URLs increases attack surface and could facilitate open-redirect attacks that assist CSRF, making the application more vulnerable, not less.

BEnsure all HTML tags are enclosed in angle brackets, e.g., "<" and ">".

Ensuring HTML tags use angle brackets is a basic HTML syntax requirement and has no bearing on CSRF prevention.

CValidate and filter input on the server side and client side.Correct

Validating and filtering input on both the server side and client side ensures that requests contain expected, well-formed values, making it harder for a forged request to pass validation checks. Server-side validation is mandatory because client-side controls can be bypassed.

DUse a web proxy to pass website requests between the user and the application.

A web proxy passes requests between user and application but does not inherently add CSRF tokens or validate request origin, so it does not prevent CSRF.

ERestrict and sanitize use of special characters in input and URLs.Correct

Restricting and sanitizing special characters in inputs and URLs prevents attackers from embedding malicious payloads or manipulating request parameters in crafted URLs that could trigger unintended actions on behalf of an authenticated user.

Concept tested: Cross-site request forgery (CSRF) prevention techniques

Source: https://owasp.org/www-community/attacks/csrf

Topics

#CSRF#input validation#server-side filtering#web application security

Community Discussion

No community discussion yet for this question.

Full SY0-301 Practice