Apache HTTPD / Request identity and configuration foundations / Lesson 7
Method restrictions in directory context
Constrain HTTP methods in a directory while testing the effective authorization and filesystem boundary.
On this page
Lesson goals
- Explain the scope of LimitExcept.
- Apply an illustrative method restriction in a directory.
- Test allowed and denied methods without broadening access.
Define the method policy
HTTP method restrictions should follow the actual resource contract. A static directory may need only reads, while an application endpoint may legitimately need writes handled elsewhere. Apache authorization sections can constrain methods, but they do not replace filesystem permissions, application authorization or a complete virtual-host review. Identify the real directory and its effective configuration before making a change.
Restrict an illustrative directory
The first fragment assumes an isolated static directory under a virtual host. It grants access to the directory generally and denies methods other than GET and HEAD using LimitExcept. Apache treats GET and HEAD together for this directive, so both are shown for clarity. Review all applicable authorization sections and module requirements; do not copy the broad access grant to a sensitive directory.
<Directory "/srv/example/public">
Require all granted
<LimitExcept GET HEAD>
Require all denied
</LimitExcept>
</Directory>
The path, modules and other authorization rules must be reviewed in an isolated configuration. Do not use this broad grant for sensitive content.
Test the allowed path
The second fragment sends a GET and a POST to a synthetic local endpoint. It is an illustration of test commands, not proof of a running server. Replace the hostname and path only in an owned test environment, inspect status and response content, and confirm the fileโs filesystem permissions. A GET returning 200 does not prove that sibling files or other methods are correctly protected.
curl -i http://127.0.0.1:8080/example.txt
curl -i -X POST http://127.0.0.1:8080/example.txt
These commands assume a controlled test server and do not modify it. Inspect the returned status and safe response separately.
Review inherited rules
Apache combines configuration sections according to their context and ordering. A parent Directory rule, an Alias target or a more specific section can affect the effective result. Inspect the actual mapped filesystem path and loaded modules, validate the configuration, and test the intended virtual host. A method restriction should not be used as the sole defense for secrets or administrative endpoints.
Check positive and negative behavior
In a disposable configuration, request a permitted file with GET and HEAD, then test a disallowed method and a protected sibling path. Record status, Allow or other relevant headers where present, and the absence of an unintended write. Validate syntax before reload and repeat through any proxy. A syntax check proves parsing under the loaded modules, not the intended access outcome.
Common errors and fixes
A protected file becomes public
- Why it happens
- A broad Require all granted was copied into a sensitive directory.
- How to fix it
- Restrict access using the intended authorization policy and filesystem boundary.
- Prevent it next time
- Test permitted and denied sibling paths.
A method is unexpectedly allowed
- Why it happens
- The effective section or mapped directory differed from the assumption.
- How to fix it
- Inspect merged configuration and the actual filesystem target.
- Prevent it next time
- Test each relevant method through the real virtual host.
A configuration test is treated as an access test
- Why it happens
- Syntax validation was assumed to prove request behavior.
- How to fix it
- Send controlled positive and negative requests after validation.
- Prevent it next time
- Retain a small method and path matrix.
2 practice exercises
1. Does denying POST in one Directory section protect a proxied API elsewhere?
Show worked solution
No. The directive applies in its configured context and the API may be mapped or handled elsewhere. Trace the selected virtual host and handler, then test the APIโs own authentication and method contract.
2. Why test a denied sibling file after granting access to a static directory?
Show worked solution
A broad directory grant can cover more files than intended. Verify the actual filesystem path and more specific rules, and assert that protected content remains unavailable.
Key takeaways
- Method restrictions are scoped configuration, not complete authorization.
- Validate syntax and test actual requests independently.