Secure File Upload & Storage - Cyber Security

  1. Which redesign BEST closes the security gap in this workflow?
    Answer: Keep objects private in a quarantine state, scan them, and atomically publish only objects that pass all required checks. When you see a workflow where files are publicly accessible before a security check completes, you're looking at a race condition vulnerability — specifically, a Time-of-Check to Time-of-Use (TOCTOU) gap. The fix is always to restrict access until validation passes, not to patch around the exposure window. Option A is correct because it eliminates the gap entirely using a quarantine-then-publish pattern. Objects stay private and inaccessible until they pass all security checks, at which point they're atomically moved to public availability. No malicious file ever has a live public URL, so there's no window for a user to download malware — even briefly. Option B is a trap. Shortening the URL's expiration reduces the exposure window but doesn't eliminate it. A fast attacker (or an automated script) can still retrieve and spread the malware within those few minutes. Security gaps measured in seconds are still gaps. Option C confuses integrity with security. Checksums verify that a file hasn't been corrupted or altered, but a malware-laden file will pass a checksum comparison perfectly — because the checksum matches the original malicious content. This catches tampering, not malware. Option D is wishful thinking. Relying on clients to voluntarily wait is not a security control — it's an honor system. Any client ignoring that suggestion gets the unscanned file immediately. Study tip: On security exam questions, whenever you see a "scan after publish" workflow, your instinct should be "quarantine first." Legitimate content tolerates a short delay; malware exploits every second of public exposure. Default-deny is always stronger than default-allow-then-remediate.
  2. Which correction is MOST important for preventing cross-tenant disclosure?
    Answer: Perform object-level authorization against the tenant and user on every retrieval before issuing or streaming the object. When you see a question about multi-tenant systems leaking data between customers, you're being tested on access control — specifically, whether authorization checks are scoped correctly. The key question to ask is: "Even if a user is authenticated, are they authorized to access this specific resource?" The flaw described is a classic Insecure Direct Object Reference (IDOR): the system confirms a user is logged in but never verifies that the requested object belongs to their tenant. Any authenticated user from Tenant A can simply request an identifier belonging to Tenant B and receive that object. The fix is D — enforcing object-level authorization on every retrieval, confirming the requesting user's tenant matches the object's owner before returning anything. This closes the logical gap directly. The distractors each address real security concerns, but none of them fix the core authorization flaw. A validates file type and Content-Type, which guards against malicious uploads or content-sniffing attacks — it does nothing to stop a legitimate user from reading another tenant's data. B suggests longer, harder-to-guess identifiers, which reduces discoverability but doesn't eliminate the risk — a determined attacker or even an accidental collision still results in unauthorized disclosure, and "hard to guess" is not the same as "access controlled." C rotates encryption keys more frequently, which is a good key-management practice but irrelevant here — the system already decrypts and returns the plaintext object on request, so key rotation protects nothing against this attack. For the exam, remember: obscurity and encryption are not substitutes for authorization. If a question describes missing ownership checks, the answer almost always involves enforcing them explicitly.
  3. Which additional design MOST effectively reduces the impact of this class of attack?
    Answer: Run a patched decoder in a low-privilege sandbox with resource limits, then publish only newly re-encoded output rather than the original file. When evaluating defenses against memory-corruption attacks in media processing, think in terms of blast radius: if the vulnerability will be exploited, what limits the damage? Signature checks and input validation help at the gate, but a sufficiently complex, valid-looking JPEG can still trigger a heap overflow inside a native library. The real question is what happens after that. Option C addresses this directly. Running a patched decoder inside a low-privilege sandbox with resource limits means that even a successful exploit is confined — the attacker can't pivot to the broader system because the process has no meaningful permissions or resources to abuse. Crucially, publishing only freshly re-encoded output (not the original file) eliminates polyglot or embedded-payload risks entirely, since the output is generated fresh from parsed image data. Option A focuses on filename extensions and dimension checks. These are trivially bypassed — a malicious JPEG can have a valid filename and legal dimensions while still containing a corrupt internal structure that triggers the library bug. Logging oversized requests catches nothing here. Option B re-verifying the JPEG signature before thumbnail generation is redundant. The attack isn't hiding from signature checks; it passes them. The exploit lives in the parsing complexity of a structurally valid but malicious file. Option D encrypts the file at rest, which protects stored data confidentiality — a separate concern entirely. Decryption inside an isolated process doesn't prevent the decoder from being exploited; it just moves where the vulnerability fires. Your study tip: when a question involves native code processing untrusted input, sandboxing + re-encoding is the gold-standard defense. Containment beats prevention when vulnerabilities are assumed inevitable.
  4. Which design change would provide the STRONGEST protection against an uploaded file becoming server-side executable content after a configuration error?
    Answer: Store uploads outside the document root and return them through a download service that never invokes application-language handlers. When evaluating file upload security, the key question isn't just "how do we block bad uploads?" but rather "what happens if every other control fails?" Defense-in-depth thinking means identifying which control eliminates the root cause of the threat rather than just mitigating symptoms. The real danger here is that uploaded files sit inside a directory where the web server can execute them. Option A eliminates this threat at its root: if uploads live outside the document root entirely and are returned through a controlled download service, the web server never has the opportunity to execute them — regardless of filename, extension, permissions, or future configuration mistakes. No configuration error can accidentally make those files executable because they're structurally unreachable by the web server's request handler. That's the strongest possible guarantee. Option B (removing execute permissions) sounds reasonable, but file execution on modern web servers is controlled by the server process owner, not filesystem execute bits. PHP files are typically executed by Nginx invoking PHP-FPM, which reads the file as data — execute permission bits don't stop this. Option C (appending a validated extension) only addresses naming, not location. A file named shell.php.jpg could still become dangerous if a misconfigured handler matches on any .php occurrence in the path, which is a real-world attack pattern. Option D (directory-level config disabling PHP) is a configuration-based control — exactly the kind of thing a later configuration change can override or undo, which is the very scenario the question describes. A useful rule of thumb: when a question asks for the strongest protection, look for the answer that removes the attacker's capability entirely rather than adding another rule layer that can be misconfigured away.
  5. Which control set BEST addresses this denial-of-service condition?
    Answer: Stream extraction while enforcing cumulative expanded-size, entry-count, nesting-depth, and resource limits in an isolated workspace. When you see a question about file upload vulnerabilities causing resource exhaustion, you're being tested on zip bomb (or archive bomb) defenses — attacks where a tiny compressed file expands into enormous data, overwhelming disk, memory, or CPU before any security scan can run. The scenario describes exactly this: a malicious archive defeats malware scanning by exhausting disk space during extraction. The fix must prevent runaway expansion during extraction, not after. Answer B addresses this directly by streaming extraction while simultaneously enforcing multiple resource limits — expanded size cap, entry count, nesting depth, and overall resource usage — inside an isolated workspace. This multi-layered approach stops the expansion mid-process before damage occurs, so the malware scan can actually complete. Answer A is tempting but fundamentally misses the threat. Adding disk capacity just raises the ceiling — a sophisticated zip bomb can still exhaust any fixed capacity. Rejecting archives by compressed size doesn't help because the attack's danger is in the expanded size, not the compressed size. Answer C addresses file-type validation (extension and Content-Type matching), which guards against disguised file types but does nothing to limit how much an archive expands. A valid .zip file can still be a zip bomb. Answer D scans before extraction, which sounds logical, but the attack already demonstrates that extraction itself causes the denial-of-service — scanning the compressed form doesn't detect the expansion risk, and deleting files afterward is too late. Study tip: When evaluating defenses against archive-based attacks, always ask whether the control acts during extraction with enforced limits, not merely before or after — attackers exploit the extraction process itself.
  6. Which approach BEST prevents path traversal and filename-collision problems?
    Answer: Generate an opaque server-side storage identifier and retain the submitted filename only as separately encoded display metadata. When a question asks about sanitizing user-supplied filenames, you should immediately think about two separate problems: input validation and storage architecture. The most robust defenses eliminate the attack surface entirely rather than trying to filter every possible malicious input. The core insight here is that any sanitization strategy applied to a user-controlled filename is playing catch-up against an attacker. Encoded slashes (%2F), Unicode normalization quirks, null bytes, and OS-specific path separators all create edge cases where "cleaned" filenames can still escape the intended directory. Option C sidesteps this entirely — by generating an opaque server-side identifier (like a UUID) as the actual storage key, the user's input never touches the filesystem path. The original filename is stored separately as metadata, safely encoded for display. This eliminates both path traversal and filename-collision risks in one architectural decision. Option A is a trap because it assumes one decode pass is sufficient. Attackers can double-encode sequences (e.g., %252F decodes first to %2F, then to /), and cross-OS normalization differences mean your strip-then-check logic may behave differently on Windows versus Linux. Option B sounds appealing — allowlists are generally better than denylists — but preserving a user-supplied name as the physical storage key still risks collisions (two users uploading report.pdf) and subtle bypass techniques if the allowlist misses an edge case. Option D is arguably the worst: canonicalizing the path after the fact is exactly what path traversal attacks exploit, and checking only the original filename's first character ignores everything that happens during normalization. Your study tip: when you see "sanitize user input before using it in a filesystem path," the gold-standard answer almost always involves not using that input as the path at all — generate your own identifier instead.
  7. Which workflow provides the STRONGEST control over direct uploads?
    Answer: Sign a server-generated, tenant-scoped key with upload constraints, then verify object attributes and security scan status before marking it available. When securing direct-upload workflows, think beyond the presigned URL itself. The real threat model includes malicious clients who control the key name, declare false metadata, and exploit the window between URL issuance and object availability. Strong control means the server owns every security-sensitive decision, not the client. Answer B is correct because it chains multiple enforcement layers together. The server generates a tenant-scoped key, eliminating path traversal or key-collision attacks a client could craft by choosing their own key. Upload constraints baked into the signature (size limits, allowed content types) are cryptographically enforced by the storage service. Critically, the object is only marked available after attribute verification and a security scan — meaning malware or policy-violating files never become accessible to other tenants, even briefly. Answer A sounds reasonable, but a short validity window and logging are detective controls at best. Logging tells you an attack happened; it doesn't prevent a valid-but-malicious payload from being uploaded and immediately accessed before anyone reviews the logs. Answer C is the most dangerous misconception. A valid signature proves the request was authenticated, not that the content is safe or accurately described. A client can carry a valid signature while uploading a 10 GB executable labeled as a 10 KB JPEG. Answer D is the scenario described as the problem in the passage — marking objects available immediately and cleaning up afterward creates a race-condition window where malicious content is briefly live and accessible. Your takeaway: whenever you see presigned URL questions, look for "server-generated keys + pre-availability verification." If the client controls metadata or the object is marked available before scanning, that's a red flag.
  8. Which additional control would MOST directly address the remaining file-type validation risk?
    Answer: Verify the file signature and parse the document with a maintained PDF parser, rejecting malformed or prohibited PDF features. When a question asks about file upload validation, think in layers: client-supplied metadata (filename, Content-Type) is completely attacker-controlled and proves nothing about what's actually inside the file. The real risk here is that a malicious file disguised as a PDF could be stored and later opened by an employee — a classic polyglot or malicious document attack. The strongest control is A: verifying the file's magic bytes (its internal signature) and parsing it with a hardened PDF library. This confirms the file is actually a PDF at a structural level, not just labeled as one. Rejecting malformed content or dangerous embedded features (like JavaScript or embedded executables within the PDF) addresses the root threat — that an attacker uploads a crafted file that survives surface checks but executes malicious behavior when opened. B is dangerously weak because a single antivirus engine misses novel, zero-day, or cleverly obfuscated malware routinely. A clean scan is not a guarantee of safety, and this creates false confidence. C doesn't help at all with file-type validation. Randomizing the filename is a good practice to prevent path traversal and enumeration, but it does nothing to verify the file's actual content or structure — the internal threat remains unchanged. D is a blocklist approach targeting executable extensions within the filename, but a skilled attacker simply avoids those strings. Blocklists are inherently incomplete; they can't anticipate every evasion technique and don't examine file contents. Study tip: On security exams, always favor controls that validate content over controls that validate labels. Attackers control labels — only structural inspection reveals the truth.
  9. Which storage strategy BEST provides a clear security boundary for replacements?
    Answer: Store each approved replacement under a new immutable key and atomically update the authorized metadata pointer after validation. When evaluating file-replacement security in storage systems, you should focus on atomicity, immutability, and validation boundaries — the core properties that prevent readers from ever observing an unvalidated or partially-replaced file. The safest design, and the reasoning behind answer D, is to treat each approved file as immutable. By writing the replacement to a brand-new key and only updating the authoritative metadata pointer after validation succeeds, you create a hard security boundary: no reader can access the new content until it has been fully approved. The swap is atomic — either the pointer updates completely or it doesn't — eliminating race conditions and ensuring consistent, validated content under the canonical URL at all times. A is dangerous precisely because it inverts the validation order. Writing to the live key before the scan passes means real users could download malicious content during the window between upload and scan completion. A "restore if scan fails" approach is reactive, not preventive — and restores may themselves fail. B improves on A by scanning first, but overwriting a live key still creates a brief inconsistency window. Cache purge requests are not instantaneous or guaranteed; during propagation, different CDN edge nodes serve different file versions, breaking integrity guarantees. C is a cosmetic workaround, not a security control. Appending a timestamp to the filename changes what the user sees in the response but doesn't establish any validated state boundary or prevent access to unvalidated content on the server side. Study tip: Watch for questions that distinguish reactive security (fix problems after they occur) from preventive security (design systems so problems can't occur). Immutable keys with atomic pointer swaps are the classic preventive pattern for safe content replacement.
  10. Which change MOST effectively limits the consequences of a malicious uploaded HTML file while preserving downloads?
    Answer: Serve uploads from a dedicated cookieless origin, use attachment disposition, and send a no-sniff response header. When a platform serves user-uploaded files from the same origin as authenticated sessions, you're dealing with a stored Cross-Site Scripting (XSS) / content injection threat. The core question becomes: how do you neutralize a malicious HTML file without breaking legitimate downloads? Think in terms of three independent defenses — origin isolation, disposition control, and MIME enforcement — and recognize that the strongest answer layers all three. Option A does exactly that. Serving uploads from a dedicated cookieless origin (e.g., uploads.example-cdn.com) ensures that even if an attacker's HTML executes JavaScript, it has no access to authentication cookies scoped to the parent domain. The Content-Disposition: attachment header forces browsers to download rather than render files. And X-Content-Type-Options: nosniff prevents browsers from ignoring the declared MIME type and speculatively rendering HTML. Together, these three controls eliminate the attack at the cookie theft, execution, and rendering layers simultaneously. Option B is a trap — randomizing filenames obscures the URL but doesn't prevent rendering. An attacker who receives a share link still gets a browsable, cookie-accessible HTML page. Option C is equally flawed. Letting the uploader declare the Content-Type means the attacker simply declares text/html themselves. This adds zero protection. Option D actually worsens the situation. Serving from the parent domain over HTTPS still exposes authentication cookies to any executed script. Short cache lifetimes address availability, not security. The study tip here: when evaluating upload-handling scenarios, always check whether the file can execute (rendering vs. download), what credentials are exposed (same-origin cookies), and whether MIME sniffing is suppressed — layered controls beat any single fix.

Start this quiz