Skip to content

Comments

Validate the Canonical field#44

Merged
spaze merged 1 commit intomainfrom
spaze/validate-canonical
Dec 6, 2025
Merged

Validate the Canonical field#44
spaze merged 1 commit intomainfrom
spaze/validate-canonical

Conversation

@spaze
Copy link
Owner

@spaze spaze commented Dec 6, 2025

If this field appears within a "security.txt" file and the URI used to retrieve that file is not listed within any canonical fields, then the contents of the file SHOULD NOT be trusted.

https://www.rfc-editor.org/rfc/rfc9116#name-canonical

Close #40

@spaze spaze self-assigned this Dec 6, 2025
Copilot AI review requested due to automatic review settings December 6, 2025 14:36
> If this field appears within a "security.txt" file and the URI used to retrieve that file is not listed within any canonical fields, then the contents of the file SHOULD NOT be trusted.

https://www.rfc-editor.org/rfc/rfc9116#name-canonical

Close #40
@spaze spaze force-pushed the spaze/validate-canonical branch from 83219d9 to b30deb8 Compare December 6, 2025 14:38
@spaze spaze merged commit 8c446c1 into main Dec 6, 2025
16 checks passed
@spaze spaze deleted the spaze/validate-canonical branch December 6, 2025 14:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements validation of the Canonical field according to RFC 9116, which states that if a security.txt file contains canonical fields, the URI used to retrieve the file should be listed within those canonical fields.

Key changes include:

  • Added file location tracking to SecurityTxt objects
  • Renamed SecurityTxtSchemeNotHttps to SecurityTxtFileLocationNotHttps for better clarity
  • Introduced SecurityTxtCanonicalUriMismatch violation when the file location doesn't match any canonical URIs
  • Added CanonicalUriListedFieldValidator to validate canonical URI consistency
  • Moved HTTPS scheme validation from fetcher to parser/SecurityTxt class

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Validator/Validators/CanonicalUriListedFieldValidator.php New validator that checks if file location matches canonical URIs
src/Validator/SecurityTxtValidator.php Added CanonicalUriListedFieldValidator to the list of validators
src/Violations/SecurityTxtCanonicalUriMismatch.php New violation for canonical URI mismatch with dynamic messaging
src/Violations/SecurityTxtFileLocationNotHttps.php Renamed from SecurityTxtSchemeNotHttps for consistency
src/Violations/SecurityTxtFileLocationNotUri.php New violation for invalid file location URIs
src/SecurityTxt.php Added fileLocation property and methods; refactored setValue/setFieldValue methods
src/Parser/SecurityTxtParser.php Updated parseString to accept optional fileLocation parameter
src/Json/SecurityTxtJson.php Added fileLocation handling in JSON serialization/deserialization
src/Fetcher/SecurityTxtFetcher.php Removed HTTPS validation (moved to SecurityTxt class)
tests/Validator/SecurityTxtValidatorTest.phpt Added comprehensive tests for canonical URI validation scenarios
tests/SecurityTxtTest.phpt Added tests for setFileLocation method
tests/Json/SecurityTxtJsonTest.phpt Added tests for fileLocation JSON handling
tests/Check/*.phpt Updated tests to use renamed SecurityTxtFileLocationNotHttps class

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

spaze added a commit to spaze/michalspacek.cz that referenced this pull request Dec 10, 2025
That means that the request will always redirect `/.well-known/security.txt` to the "main site" (with `www`, or without).

Because spaze/security-txt has introduced validation of the `Canonical` field in spaze/security-txt#44 and when it doesn't match, a warning is generated.

Another option would be to add extra `Canonical` (e.g. with `www`) to the `security.txt` file, or to redirect directly in nginx, but that would mean having redirect rules, like is this domain used with or without `www`, in one more place. Let's see if this is a good idea.
spaze added a commit to spaze/michalspacek.cz that referenced this pull request Dec 10, 2025
That means that the request will always redirect `/.well-known/security.txt` to the "main site" (with `www`, or without).

Because spaze/security-txt has introduced validation of the `Canonical` field in spaze/security-txt#44 and when it doesn't match, a warning is generated.

Another option would be to add extra `Canonical` (e.g. with `www`) to the `security.txt` file, or to redirect directly in nginx, but that would mean having redirect rules, like is this domain used with or without `www`, in one more place. Let's see if this is a good idea.
spaze added a commit to spaze/michalspacek.cz that referenced this pull request Dec 10, 2025
That means that the request will always redirect `/.well-known/security.txt` to the "main site" (with `www`, or without).

Because spaze/security-txt has introduced validation of the `Canonical` field in spaze/security-txt#44 and when it doesn't match, a warning is generated.

Another option would be to add extra `Canonical` (e.g. with `www`) to the `security.txt` file, or to redirect directly in nginx, but that would mean having redirect rules, like is this domain used with or without `www`, in one more place. Let's see if this is a good idea.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate the Canonical field

1 participant