Skip to main content

SecTXT: Security.txt parser and validator

This package contains a security.txt (RFC 9116) parser and validator.

Installation

The package is available on pypi. It can be installed using pip:

> python -m pip install sectxt

Usage

>>> from sectxt import SecurityTXT
>>> s = SecurityTXT("www.example.com")
>>> s.is_valid()
True

Validation

>>> from sectxt import SecurityTXT
>>> s = SecurityTXT("www.example.com")
>>> s.errors
[{'code': 'no_uri', 'message': 'The field value must be an URI', 'line': 2}, {'code': 'no_expire', 'message': 'The Expires field is missing', 'line': None}]
>>> s.recommendations
[{'code': 'long_expiry', 'message': 'Expiry date is more than one year in the future', 'line': 3}]

The "errors" and "recommendations" attribute return a list of entries. An entry is a dict with three keys:

key value
code A fixed error code string
message A human readable error message in English
line The 1 based integer line number where the error occurred or None when the error applies to the entire file

Possible errors

code message
"no_security_txt" "Security.txt could not be located."
"location" "Security.txt was located on the top-level path (legacy place), but must be placed under the '/.well-known/' path."
"invalid_cert" "Security.txt must be served with a valid TLS certificate."
"no_content_type" "HTTP Content-Type header must be sent."
"invalid_media" "Media type in Content-Type header must be 'text/plain'."
"invalid_charset" "Charset parameter in Content-Type header must be 'utf-8' if present."
"utf8" "Content must be utf-8 encoded."
"no_expire" "'Expires' field must be present."
"multi_expire" "'Expires' field must not appear more than once."
"invalid_expiry" "Date and time in 'Expires' field must be formatted according to ISO 8601."
"expired" "Date and time in 'Expires' field must not be in the past."
"no_contact" "'Contact' field must appear at least once."
"no_canonical_match" "Web URI where security.txt is located must match with a 'Canonical' field. In case of redirecting either the first or last web URI of the redirect chain must match."
"multi_lang" "'Preferred-Languages' field must not appear more than once."
"invalid_lang" "Value in 'Preferred-Languages' field must match one or more language tags as defined in RFC5646, separated by commas."
"no_uri" "Field value must be a URI (e.g. beginning with 'mailto:')."
"no_https" "Web URI must begin with 'https://'."
"prec_ws" "There must be no whitespace before the field separator (colon)."
"no_space" "Field separator (colon) must be followed by a space."
"empty_key" "Field name must not be empty."
"empty_value" "Field value must not be empty."
"invalid_line" "Line must contain a field name and value, unless the line is blank or contains a comment."

Possible recommendations

code message
"long_expiry" "Date and time in 'Expires' field should be less than a year into the future."
"no_encryption" "'Encryption' field should be present when 'Contact' field contains an email address."
"not_signed" "File should be digitally signed."
"no_canonical" "'Canonical' field should be present in a signed file."
"unknown_field" "Unknown field name '{name}'. Permitted, but not syntax checked and probably widely unsupported."

According to RFC 9116 section 2.4, any fields that are not explicitly supported should be ignored. This parser does add a recommendation for unknown fields by default. This behaviour can be turned off using the parameter recommend_unknown_fields:

>>> from sectxt import SecurityTXT
>>> s = SecurityTXT("www.example.com", recommend_unknown_fields=False)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sectxt-0.5.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sectxt-0.5-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file sectxt-0.5.tar.gz.

File metadata

  • Download URL: sectxt-0.5.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for sectxt-0.5.tar.gz
Algorithm Hash digest
SHA256 c5b607bdd2955674d417266d6e41bed9d08d2e02648964d1109a0922a34b104c
MD5 c4c05e7bf56dead09dfbab287b7f09fb
BLAKE2b-256 d77ee06c617c09125d8e0010391dce76eac36b5ef25e6474d13312d87d5a9f2f

See more details on using hashes here.

File details

Details for the file sectxt-0.5-py3-none-any.whl.

File metadata

  • Download URL: sectxt-0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for sectxt-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ff60e65de104479765f87bcba719e4011b982ffb9469801f240bd94bf4a57909
MD5 a7a2c2b97ec3f604c82dad1369d8cc9a
BLAKE2b-256 5539af2b83ac89e8c969d291369ef119e45a16edfc550d65b2c08a31d00d2775

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.8

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8

2 files

0.7

2 files

0.6

2 files

This release

0.5 This release

2 files

0.4

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page