Engineering / Field note
A Windows file handle proves only the access it requested
Five fictional review records explain attribute access, two-way sharing checks and the difference between a file handle and a stable path.
An open Windows handle is evidence of a particular access request. The word exclusive can make that sound broader than it is. When software relies on a handle to protect an input file, the useful question is which competing operations the requested access and sharing combination actually constrains. A successful open is the beginning of that explanation, rather than the whole explanation.
Microsoft's CreateFileW reference separates desired access from sharing mode and explicitly exempts attribute and extended-attribute access requests from the sharing flag's restrictions. That detail matters when a helper opens something only to inspect its metadata. The absence of share flags should not, by itself, become a claim that the helper has established every kind of content or path protection. [1]
This is a review of established Windows API behavior, checked on November 29, 2026. The CreateFileW reference carries a February 9, 2023 update date. The five original JSON records below are fictional review examples, not executable API calls or measurements from a real application. They show how to describe a capability without quietly promoting it into a larger guarantee. [1]
Start by spelling out the access category. Microsoft defines FILE_READ_ATTRIBUTES separately from FILE_READ_DATA and FILE_LIST_DIRECTORY. Reading metadata, reading file contents and enumerating a directory are different requests. Our recommendation is to keep those names visible in the design review, especially when a convenient wrapper describes all three activities with a friendly verb such as open. [3]
{
"fictional_example": true,
"target_kind": "file",
"desired_access": [
"FILE_READ_ATTRIBUTES"
],
"share_mode": [],
"intended_use": "inspect attributes",
"content_read_access_requested": false,
"exclusive_content_guard_established": "not demonstrated by this record"
}The first record deliberately stops at the access request. It does not say that a particular rename succeeded or that an attacker can replace an input. Those would require separate observations. A precise description leaves the next engineer with a testable question instead of a promise whose scope nobody can quite reconstruct.
Sharing compatibility also works in both directions. Microsoft's opening-files guide compares the new request with existing handles' access and sharing modes. Two readers can conflict if the second reader refuses to share the read access already held by the first. The guide's compatibility table is a better starting point than the intuition that reading can never bother another reader. [2]
{
"fictional_example": true,
"existing": {
"access": [
"GENERIC_READ"
],
"share": [
"FILE_SHARE_READ"
]
},
"candidate": {
"access": [
"GENERIC_READ"
],
"share": []
},
"sharing_check": "incompatible",
"alternative_candidate_share": [
"FILE_SHARE_READ"
],
"other_permission_checks": "still required"
}Treat this as a sharing-layer example. It does not assert that the alternative open must succeed on every machine: permissions, the target and other conditions still matter. For a reusable library, documenting both columns is valuable. A later caller should be able to tell whether its own restrictive sharing choice changes the behavior it is trying to preserve.
Next, distinguish requesting delete access from completing a rename. CreateFileW documents FILE_SHARE_DELETE in terms of subsequent delete-access requests and notes that delete access supports deletion and renaming. Our interpretation is narrower than an end-to-end path claim: an accepted handle request describes that step; the actual operation and its result remain separate evidence. [1]
{
"fictional_example": true,
"target_kind": "directory",
"delete_access_open": "succeeded in this fictional case",
"rename_attempted": false,
"rename_result": "not observed",
"conclusion": "rename capability remains unproven"
}A path also contains more than its final file. If the requirement is that a consumer resolves a particular input throughout a handoff, ask what is established about the relevant directory entries and the consumer's lookup. The example above avoids treating a successful preliminary open as a completed rename, or a file-content check as a complete path-stability check.
Directory handles have their own opening requirements. Microsoft's reference specifies FILE_FLAG_BACKUP_SEMANTICS for opening a directory with CreateFileW; it also explains that ordinary security checks still apply without the associated backup and restore privileges. Merely adding that flag does not answer the access-and-sharing question for the directory. [1]
{
"fictional_example": true,
"target_kind": "directory",
"creation_disposition": "OPEN_EXISTING",
"flags": [
"FILE_FLAG_BACKUP_SEMANTICS"
],
"access_and_share_review": "required",
"file_content_claim": "outside this directory-open record",
"ancestor_path_stability": "requires a separate design and test"
}Finally, compare the relevant operation before, during and after the proposed protection. Choose a disposable fixture and keep the user, target and requested operation consistent. If the baseline already fails, another failure during the protected phase tells you little about the mechanism. This is our testing recommendation, not a claim that the JSON format below is a Windows feature.
{
"fictional_example": true,
"operation": "open fixture for data writing",
"fictional_outcomes": {
"before": "success",
"while_guard_open": "sharing violation",
"after_close": "success"
},
"supports": "this write-open comparison",
"does_not_establish": [
"all rename cases",
"all parent-directory operations"
]
}The practical benefit is a smaller, clearer contract. A caller can ask for the access it needs; a reviewer can examine the competing operation; and a test can report what it actually demonstrated. That keeps a useful file handle from being asked to moonlight as a universal lock. The API has a specific job, and the surrounding design still has one too.
Sources + further reading
Source dates describe the original material. Publication above is the date this Zyel article went live.
- CreateFileW: requested access, sharing modes and directory handlesMicrosoft · Checked Nov 29, 2026
- Creating and Opening Files: compatible access and sharing combinationsMicrosoft · Checked Nov 29, 2026
- File Access Rights Constants: attributes, data and directory accessMicrosoft · Checked Nov 29, 2026
Reader discussion
What would you ask next?
Questions, useful corrections and thoughtful disagreement are welcome. Comments are reviewed before they appear.
No reader comments yet.