Join our Newsletter — 33% off our NHI Course
Home› FAQ› Architecture & Implementation› How do developers prevent files or directories from…
Architecture & Implementation

How do developers prevent files or directories from being accessible to external parties?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 18, 2026 Domain: Architecture & Implementation

Developers prevent this by enforcing server-side authorisation on every request and never relying on hidden paths, predictable names, or client-side checks. Store sensitive files outside the public web root, deny directory listing, validate requested paths, and ensure each file or directory is checked against the caller’s entitlement before access is granted.

Why external access control must happen on the server

The core mistake is assuming that obscurity creates protection. Hidden routes, renamed folders, and client-side logic only reduce discoverability, they do not enforce entitlement. The server has to decide, on every request, whether the caller may read the file or enumerate the directory, and that decision must be independent of what the browser shows or what the client can guess.

That is why secure file access starts with mediation, not presentation. A request for a document, export, backup, or uploaded asset should be treated like any other protected resource request: the path is resolved, the caller is identified, and the entitlement check happens before the file stream or directory contents are returned. If the check is missing, predictable naming and exposed paths become an access-control failure rather than a convenience issue.

Store protected content outside the public web root whenever possible, because that removes the default assumption that every web-accessible path is readable. When files must remain addressable through the application, the application should translate a logical identifier into a server-side lookup and compare that lookup against the caller’s rights before opening the resource. That design is more reliable than trying to hide the file name.

What breaks when paths and directories are treated as secrets

Directory listing is a separate control from file access, but it fails for the same reason: the server exposes information without checking whether the requester should see the collection at all. If directory browsing is enabled, an attacker may discover filenames, backup copies, staging artefacts, or adjacent resources that were never meant to be public. If path validation is weak, traversal tricks can move the request outside the intended area.

Validate requested paths against an allowlist of expected locations, canonicalise the path before comparison, and reject anything that resolves outside the permitted scope. That matters because many file exposure bugs are not about one secret document, they are about a whole class of predictable names, alternate encodings, and inherited filesystem permissions that make “hidden” content reachable anyway. CWE Top 25 Guide is useful background here because path traversal, missing authorisation, and insecure permission handling are recurring root causes in software weaknesses. OWASP API Security Top 10 also reinforces the same principle for resource access: a caller must not be able to reach an object, file, or function just by guessing its identifier.

Predictable naming is especially dangerous when the application exposes generated reports, invoices, exports, logs, or uploaded media by direct URL. If the name or location can be guessed, then “not linked from the UI” is not a control. The control is whether the server checks entitlement on access and whether the request can be forced to stay inside the intended resource boundary.

How to keep file access safe when the application serves the content

When the application must serve files, build the access decision into the retrieval flow. The request should identify the resource, check that the caller is allowed to access that exact resource, and only then open the file handle. Do not let the user supply a raw filesystem path unless it is normalised and mapped through a safe internal lookup. Do not trust hidden form fields, URL opacity, or JavaScript gating to protect the content.

Use least privilege on the storage layer as well. The web process should only be able to read the directories it truly needs, and it should not have broad access to unrelated application data, backups, or deployment artefacts. If a compromise happens elsewhere in the stack, narrow filesystem permissions reduce how much content can be swept up in a single request path.

OWASP Cheat Sheet Series is the best external starting point for implementation patterns around authorisation, path handling, and secure request processing. For teams that want a control-oriented baseline, NIST SP 800-53 Rev 5 Security and Privacy Controls is relevant because access control, identification, and configuration discipline all shape whether protected files stay protected. If the application uses cloud storage or shared file services, Secure File Sharing Guide helps frame the same problem in terms of sharing links, external collaborators, and stale exposure.

Risk and Threat Considerations

File exposure usually becomes serious when an application treats reachability as proof of permission. Attackers look for predictable paths, misconfigured directories, stale artefacts, and any endpoint that returns file content before checking who asked for it. Once one exposed resource is found, adjacent files often become reachable through enumeration or path manipulation.

Failure mechanism: The server trusts obscurity, path structure, or client-side controls instead of enforcing authorisation on each request, so a guessed or manipulated path returns content that should have stayed private.

Impact: Sensitive documents, backups, source files, logs, or user-generated content can be disclosed externally, and the exposure can scale quickly if directory listing or inherited permissions reveal more than one object.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV8 — AuthorizationProtecting files requires request-time access decisions.
V13 — ConfigurationDirectory listing and public-web-root exposure are configuration weaknesses.
Recommendation — Enforce per-request authorisation before serving each file or directory. Disable directory browsing and restrict web-exposed paths.
NIST SP 800-53 Rev 5AC-3 — Access EnforcementThe server must enforce who can read each protected resource.
AC-6 — Least PrivilegeMinimises filesystem reach if the web process is abused.
CM-7 — Least FunctionalityRemoves unnecessary directory browsing and exposed file services.
Recommendation — Apply access enforcement to every file retrieval request. Limit the web process to only the directories it must read. Disable directory listing and remove unneeded file exposure features.

Practitioner Guidance

What to verify: Confirm that every file-serving route performs a server-side entitlement check before the file is opened or streamed, including downloads, preview endpoints, and any “temporary” access links. Verify that protected content is not sitting under a public web root unless there is a deliberate access gate in front of it.

Common mistake: Teams often secure the user interface and forget the resource itself. That leaves direct URL access, directory browsing, backup copies, and guessable filenames as the real attack surface.

Practitioner takeaway: If a request can reach the filesystem, the filesystem is already part of the security boundary, so the decisive control is server-side authorisation plus safe path handling, not secrecy of the URL.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 18, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org