Docsity

D385 Task 2 Study Guide – Secure Coding & Secure API Implementation, Study Guides, Projects, Research of Computer Science

Partial preview of the text

Download D385 Task 2 Study Guide – Secure Coding & Secure API Implementation and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Successstudybank D385 Task 2 Study Guide — Secure Coding & Secure API Implementation | Latest Exam Preparation D385 Task 2 Study Guide — Secure Coding & Secure API Implementation successstudy 8/29/

D385 Task 2 Study Guide — Secure Coding & Secure API

Implementation | Latest Exam Preparation

CLASS: Where does Task 2 sit in D385? - ✅Correct Answer✅Second of two ZHN performance tasks: Secure Coding and Secure API Implementation - remediate the starter API, prove fixes with pytest, and write a Security Mitigation Report. Competencies: 4102.1.1 evaluate logs, 4102.1.2 develop mitigations, 4102.1. configure REST API authentication CLASS: The Task 2 scenario in one line - ✅Correct Answer✅Internal Construction Equipment Rental API (v2.2.0, endpoints under /api/v1/) is suffering unauthorized access attempts, suspicious input patterns, and failing authorization logic - you are the developer securing it CLASS: What goes in the final Task 2 submission? - ✅ Correct Answer✅ONE zip containing the written report (Word docx) plus the modified Python script and the test script - the starter tells you to save your fixed app as app_solution.py CLASS: The evidence files provided with the starter - ✅ Correct Answer✅app_student.py (vulnerable code), task_2_flake8_report.txt (general vulns for Section A), task_2_bandit_report.txt (API vulns for Section B), network_security_log.txt (attack evidence), penetration_test_report.json (fill-in template) CLASS: Security principles the task intro names - ✅ Correct Answer✅Least privilege, defense in depth, encryption, API keys, and OAuth - be ready to explain how each protects modern APIs CLASS: Course textbook to cite in the report - ✅ Correct Answer✅Full Stack Python Security by Dennis Byrne - hashing/salting, TLS, and attack chapters map directly to D1-D CLASS: The two submission gates before evaluation - ✅ Correct Answer✅WGU similarity checker (wait for the report and review it) and Grammarly for Education (submission cannot pass without professional communication passing) RUBRIC: Section A pattern (A1-A3) - ✅ Correct Answer✅Pick 2 GENERAL vulnerabilities from the flake8 report. A1 screenshot the insecure code WITH line numbers, A2 implement a secure replacement using industry practice, A3 comment out the original code so it no longer executes - never delete it RUBRIC: Section B pattern (B1-B3) - ✅ Correct Answer✅Same three-step evidence for 2 API security vulnerabilities sourced from the bandit report: insecure screenshot with line numbers, secure replacement, original commented out RUBRIC: Section C requirements (C1-C5) - ✅ Correct Answer✅C1 pytest functions named test_*, C2 assert in every test, C3 all tests pass, C4 descriptive print() lines explaining each outcome for the console screenshot, C5 four passing-test screenshots: 2 general + 2 API RUBRIC: Section D report structure (D1-D4) - ✅ Correct Answer✅D1 two mitigation strategies for EACH of the 4 remediated vulnerabilities, D2 two input validation techniques, D3 two exception handling improvements, D4 one encryption method securing application traffic RUBRIC: Why comment out instead of delete? - ✅ Correct Answer✅The evaluator must see before-and-after in the same file - proof you found the exact lines, replaced them

CODE: POST /api/v1/rentals vulnerabilities - ✅Correct Answer✅No input validation: days accepts negatives or strings (type and boundary checks missing) and new records embed an SSN field that should never be stored CODE: The admin endpoints - ✅Correct Answer✅GET /api/v1/admin/users and DELETE /api/v1/admin/delete_user have zero authentication or authorization - a destructive delete anyone can call (CWE-306, broken access control) CODE: GET /api/v1/search vulnerability - ✅ Correct Answer✅Reflects the unsanitized q parameter back in the JSON response - XSS. Fix: escape output, validate and length- limit input CODE: POST /api/v1/authenticate vulnerabilities - ✅ Correct Answer✅No rate limiting (CWE-307), plaintext password comparison against USERS_DB, and success hands back the user's api_key - combine hashing, lockout/backoff, and TLS CODE: Lines 651 - 652 - vulnerability and fix - ✅ Correct Answer✅Prints the API key to the console, then app.run(debug=True) - B201, High severity, CWE- 9 4: the Werkzeug debugger allows arbitrary code execution. Fix: remove the print and drive debug from an environment flag, default False CODE: Line 52 finding - ✅ Correct Answer✅F401 - the os module imported but unused in the pristine starter; a hygiene finding proving flake8 catches style as well as security (it becomes used once your env-var fix lands) CODE: CWE cheat row for this task - ✅ Correct Answer✅ 89 SQL injection, 94 code injection via debug, 209 verbose errors, 256 plaintext passwords, 259 hardcoded credentials, 285/862 broken authorization, 306 missing authentication, 307 no rate limiting, 359 PII exposure, 598 secrets in URLs CODE: CWE- 598 in this app - ✅ Correct Answer✅API keys sent as URL query parameters end up in logs, history, and caches - transmit keys in the Authorization header as a Bearer token instead REPORTS: The flake8 command and tallies - ✅ Correct Answer✅flake8 --max-line- length=120 --show-source --statistics app_student.py. Totals: 6x S105 hardcoded password, 1x S608 SQL injection, 1x S201 debug mode, 1x F401 unused import REPORTS: The bandit command and severity spread - ✅Correct Answer✅bandit - r app_student.py - f txt. Findings: 6 Low (all B105 hardcoded passwords), 1 Medium (B608 SQL injection at line 319), 1 High (B201 debug=True at line 652). 366 lines of code scanned REPORTS: Highest-severity bandit finding and why - ✅ Correct Answer✅B flask_debug_true - High severity because the exposed Werkzeug debugger permits arbitrary remote code execution, a full compromise from one config flag REPORTS: B105 vs S105 - ✅ Correct Answer✅The same hardcoded-password rule seen from two tools: B-prefixed IDs come from bandit, S-prefixed from the flake security plugin - one vulnerability, two report sources REPORTS: Which report feeds which rubric section? - ✅ Correct Answer✅Section A general vulnerabilities come from the flake8 report; Section B API vulnerabilities come from the bandit report - citing the wrong source loses the aspect LOG: What is network_security_log.txt? - ✅ Correct Answer✅One week of API and network events (Dec 22 - 28) ending in a security audit - the evidence base for the pen- test template and for justifying severities in your report

LOG: The audit's 10 findings summary - ✅ Correct Answer✅SQL injection in /api/v1/user, broken access control on admin endpoints, missing authentication on multiple routes, no rate limiting, hardcoded secrets, sensitive data exposure (SSN and passwords), XSS in search, missing input validation, least privilege violations, verbose error messages LOG: The Dec 23 SQL injection incident - ✅Correct Answer✅A quote-OR- 1 - equals- 1 payload in the username parameter from 198.51.100.45 returned ALL user records; a follow-up DROP TABLE probe was stopped only by database permissions - proof the code layer had no defense LOG: The Dec 24 brute force incident - ✅Correct Answer✅ 50 authentication attempts in 10 seconds against the admin account from 45.33.32.156 - succeeded because there is no rate limiting or account lockout (CWE-307) LOG: The Dec 25 DoS incident - ✅Correct Answer✅ 1000 requests in 10 seconds from a single IP drove CPU to 95 percent and response times past 5 seconds - no rate limiting meant the attack simply worked LOG: The Dec 25 deletion incident - ✅Correct Answer✅DELETE /api/v1/admin/delete_user removed user alice, called unauthenticated from an external IP - broken access control on a destructive endpoint is the single scariest log line LOG: The Dec 24 API-key-in-URL event - ✅Correct Answer✅A GET request carried api_key as a query parameter; the log itself notes keys belong in the Authorization header - live evidence of CWE- 598 LOG: The Dec 26 horizontal privilege escalation - ✅ Correct Answer✅Logged-in alice fetched bob's user data - same-role users can read each other's records because no per-resource authorization check exists LOG: The Dec 27 mass assignment event - ✅Correct Answer✅A rental POST smuggled an extra role field set to admin and the API accepted it - only accept the expected fields (allowlist the request schema) LOG: The Dec 27 boundary failures - ✅ Correct Answer✅A 10,000-character search string broke memory allocation (buffer-overflow-style, no length validation) and days of 999999 produced a half-billion-dollar rental (no boundary validation) LOG: The Dec 27 DNS hijacking indicator - ✅Correct Answer✅A suspicious DNS query for a malicious domain - possible DNS hijack or data exfiltration channel; the pen-test template asks you to explain this attack class LOG: Other exposure events worth citing - ✅Correct Answer✅SSN fields exposed in rental responses, password_hash values leaking in an API response, and a raw sqlite OperationalError string sent to a client - all D-report ammunition PENTEST: What the template requires - ✅ Correct Answer✅Findings (minimum 5 recommended) each with attack type, severity, CVSS score, endpoint, observable pattern, evidence, impact, and mitigations - plus an attack_summary, a top- 3 remediation_priority list, and REMOVE the _instructions field before submitting PENTEST: The five attack_summary classes to explain - ✅ Correct Answer✅SQL injection, buffer overflow, XSS, DNS hijacking, and DoS - each needs a description of how it works plus the indicators you observed in the network log PENTEST: CVSS bands - ✅Correct Answer✅LOW under 4.0, MEDIUM 4.0-6.9, HIGH 7.0-8.9, CRITICAL 9.0 and up - the score justifies each finding's severity and your remediation ordering