fix: check all security.txt paths before returning isPresent false #292
fix: check all security.txt paths before returning isPresent false #292Lissy93 merged 2 commits intoLissy93:masterfrom
Conversation
β Deploy Preview for web-check ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
LGTM, thanks! |
|
I didn't get the chance to explain this second commit before it was merged, so I wanted to add context here. About the second commit β User-Agent headerWhile working on the first fix, I identified a second issue: Node.js does not send a The second commit adds Reproduction: # No User-Agent (Node.js default) β server blocks, returns HTML
curl -s -A "" https://www.reddit.com/.well-known/security.txt | head -3
# β <!doctype html>
# With User-Agent: curl/8.0.0 β returns valid security.txt
curl -sL -A "curl/8.0.0" https://www.reddit.com/.well-known/security.txt | head -3
# β -----BEGIN PGP SIGNED MESSAGE----- Note on production: Despite both fixes being live, reddit.com still returns {"isPresent":false} on web-check.as93.net. The fix works correctly from a residential IP, but the production |
Bug
When
/security.txtreturns HTML (e.g. a homepage instead of a 404),the checker immediately returns
isPresent: falsewithout testing the fallback path/.well-known/security.txt(RFC 9116 standard location).Expected Behavior
The checker should attempt all known security.txt locations before concluding that it is not present.
According to RFC 9116,
/.well-known/security.txtis the canonical location and must always be checked, even if/security.txtreturns an unexpected response.Root Cause
The condition on line 56:
exits the function early, preventing the fallback path from being evaluated.
Fix
Instead of returning early, the loop continues to evaluate the remaining paths.
Impact
This causes false negatives in real-world scenarios where:
/security.txtreturns HTML (e.g. homepage or redirect)/.well-known/security.txtexists and is validAs a result, valid security.txt files are incorrectly reported as missing.
Evidence
The screenshot below shows a real case:
/security.txtreturns HTML (homepage)/.well-known/security.txtexists and is validRelated
Relates to #189, but addresses the issue more precisely.
Removing the HTML check entirely (as proposed in #189) may introduce false positives by allowing HTML responses to be treated as valid.
This approach: