response = requests.get(url)
Users can specify the document to be parsed by passing the document URL to the application as a parameter.
Which of the following is the best solution?
Show answerHide answer
Correct answer: C Code scanner
Explanation
Explanation:The code takes a user‑supplied URL and fetches it without validation (requests.get(url)). This is a Server‑Side Request Forgery (SSRF) vulnerability. An attacker could specify internal server URLs to access sensitive documents or scan internal networks. The best solution in the development pipeline is a code scanner that detects SSRF patterns before deployment.
Correct Option:
C. Code scanner
A static application security testing (SAST) or code scanner integrated into the pipeline would flag requests.get(url) with user‑controlled input as an SSRF vulnerability. This allows the engineer to fix the issue before production. Code scanners are most effective for finding injection and request forgery flaws early in the development lifecycle.
Incorrect Option:
A. Indexing
Indexing refers to database optimization (creating indexes for faster queries) or document indexing for search. It has no relevance to preventing SSRF or validating user‑supplied URLs. Indexing does not block or detect the security issue in the code snippet.
B. Output encoding
Output encoding (e.g., HTML entity encoding) prevents cross‑site scripting (XSS) by neutralizing special characters in output. The vulnerability here is SSRF (server‑side request forgery), not XSS. Output encoding will not stop the application from making arbitrary HTTP requests to internal servers.
D. Penetration testing
Penetration testing is a manual or automated external assessment performed after deployment. It can confirm SSRF exists but does not prevent it from being introduced in the pipeline. A code scanner is better for shifting left (catching issues during development). Pen testing is reactive, not preventive.
Reference:
CompTIA CAS-005 Exam Objectives – Domain 2: Enterprise Security Architecture (Secure development, SAST, SSRF prevention). Also OWASP Top 10 – SSRF (A10:2021) and OWASP ASVS (5.3.5 – validate URLs). CWE-918 (Server‑Side Request Forgery).