Security and hardening · Beginner · 15 min
Publish a security.txt file and a vulnerability disclosure policy
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · Nginx 1.30.8 (nginx.org repo) · GnuPG 2
You will publish a signed RFC 9116 security.txt over HTTPS from Nginx, with a short disclosure policy that tells researchers what to test, how to report and what you promise in return.
On this page
Someone finds a hole in your site. They want to tell you. Where do they send it? If the answer is a contact form that goes to sales, or a Twitter account nobody watches, the report gets lost, or the finder gives up and posts it publicly. A security.txt file fixes the first half of that problem: it is a small text file at a fixed address, /.well-known/security.txt, that says who to contact and how. RFC 9116 defines it, and security researchers and scanners check for it.
The second half is a disclosure policy: a short page that tells the finder what they may test, what they must not do, that you will not take legal action against good-faith research, and how fast you will answer. Together, the two turn a stranger's discovery into a report in your inbox.
In this tutorial you will write the file with the fields that matter, sign it with an OpenPGP key so readers can check it came from you, serve it from Nginx over HTTPS with the right content type, publish a policy page, and add a check that warns you before the file expires. Replace example.com and security@example.com with your own domain and mailbox everywhere they appear.
Step 1 · Decide who receives reports
Before you write a line of the file, settle three things. A security.txt that points to a dead mailbox is worse than none, because it tells researchers you are not listening.
- The contact. Use a role mailbox such as
security@example.comthat at least two people read, not one person's address. When that person leaves or goes on holiday, reports must still land somewhere. Ahttps://link to a report form also works, and you can list several contacts in order of preference. - The languages you read. The
Preferred-Languagesfield lists the languages your team can read a report in, not languages you translate the page into. A team in Abidjan might listfr, en; a team in Nairobien, sw. If you leave the field out, readers assume English. - The addresses of the other pages. You will publish the public key at
/.well-known/pgp-key.txtand the policy at/security-policy/. Writing the addresses down now means the file and the pages agree.
Install GnuPG and curl, which the next steps use, and make a working folder for the files:
sudo apt update
sudo apt install -y gnupg curl
mkdir -p ~/security-txt-demo
cd ~/security-txt-demo
gpg --version | sed -n 1pCheck it worked
The last command prints a line starting gpg (GnuPG) 2., and ls -d ~/security-txt-demo shows the folder exists. You have written down the mailbox, the languages and the two page addresses you will use.
Step 2 · Create a signing and encryption key and export the public half
A signature lets anyone confirm that the security.txt they fetched is the one you wrote, and not one an attacker swapped in after breaking into the web server. Signing is optional in RFC 9116, but recommended, and it only takes a few commands.
Create a key for the security mailbox that signs and encrypts, valid for one year. The first command makes an ed25519 primary key that signs; the second adds a cv25519 subkey that finders encrypt their reports to. GnuPG asks for a passphrase; choose a strong one and store it in your team's password manager:
gpg --quick-generate-key "Example Security Team <security@example.com>" ed25519 sign 1y
FPR=$(gpg --list-keys --with-colons security@example.com | awk -F: '/^fpr/ {print $10; exit}')
gpg --quick-add-key "$FPR" cv25519 encr 1yIf GnuPG fails with Inappropriate ioctl for device over SSH, run export GPG_TTY=$(tty) and try again. Many teams keep this key on a laptop instead of the web server; the commands are the same, and you copy the signed file to the server afterwards.
Export the public key to a file that you will publish:
cd ~/security-txt-demo
gpg --armor --export security@example.com > pgp-key.txt
gpg --fingerprint security@example.com
head -n 1 pgp-key.txt
echo test | gpg --batch --trust-model always --armor --encrypt -r security@example.com | head -n 1Check it worked
gpg --fingerprint prints a pub ed25519 line with [SC] and an expiry date a year from today, followed by the 40-character fingerprint, and a sub cv25519 line with [E]. The first line of pgp-key.txt is -----BEGIN PGP PUBLIC KEY BLOCK-----. The test encryption prints -----BEGIN PGP MESSAGE-----, which is what a finder sees when they encrypt a report to your key.
Step 3 · Write the security.txt file
The file is plain Field: value lines. Two fields are required: Contact and Expires. Expires must appear exactly once, and should be less than a year away, so that a stale file stops being trusted on its own. This command sets it to 180 days from now, in the UTC date-time format the RFC asks for:
cd ~/security-txt-demo
EXPIRES=$(date -u -d '+180 days' +%Y-%m-%dT%H:%M:%SZ)
cat > security.txt.unsigned <<EOF
# Security contact for example.com. Please read the policy before you test.
Contact: mailto:security@example.com
Expires: $EXPIRES
Encryption: https://example.com/.well-known/pgp-key.txt
Preferred-Languages: en, fr
Canonical: https://example.com/.well-known/security.txt
Policy: https://example.com/security-policy/
Acknowledgments: https://example.com/security-policy/#credit
EOF
cat security.txt.unsignedWhat each line does:
- Lines starting with
#are comments. Keep them short. Contactis where reports go. Usemailto:,tel:or anhttps://address.Encryptionpoints to your public key so a finder can encrypt the report. It is a link to the key, never the key itself.Canonicalis the address this file is meant to live at. A reader who fetched the file from somewhere else, and does not see that address listed, should not trust it. Signing andCanonicaltogether stop someone copying your signed file to their own site.Policylinks to the disclosure policy you will write later in this tutorial.Acknowledgmentslinks to the place you credit finders.
Check it worked
The output shows your seven fields and the comment. The Expires line holds a date about six months ahead, ending in Z, such as Expires: 2027-05-25T09:14:02Z. Count the Expires lines; there must be one:
grep -c '^Expires:' ~/security-txt-demo/security.txt.unsignedThe output is 1.
Step 4 · Sign the file
Wrap the file in an OpenPGP cleartext signature. The text stays readable; GnuPG adds a header line above it and a signature block below it:
cd ~/security-txt-demo
gpg --yes --clearsign --local-user security@example.com --output security.txt security.txt.unsigned
head -n 3 security.txt
gpg --verify security.txtGnuPG asks for the passphrase you set. Every time you change the file later, edit security.txt.unsigned and run the --clearsign command again. Never edit the signed file by hand: changing one character breaks the signature.
Check it worked
head shows -----BEGIN PGP SIGNED MESSAGE-----, then Hash: SHA512 or another hash name, then an empty line. gpg --verify prints Good signature from "Example Security Team <security@example.com>".
Step 5 · Serve the files from Nginx over HTTPS
RFC 9116 requires the file to be served over HTTPS, as plain text with the UTF-8 character set. The files go in the web root your site already uses. If you followed the server blocks and Let's Encrypt tutorials, that is /var/www/example.com/html; check yours, and use the path it prints wherever this tutorial says /var/www/example.com/html:
grep -n 'root' /etc/nginx/conf.d/example.com.confCopy the two files into a .well-known folder inside that root, with permissions Nginx can read. install copies a file and sets its mode in one go:
cd ~/security-txt-demo
sudo install -d -m 755 /var/www/example.com/html/.well-known
sudo install -m 644 security.txt /var/www/example.com/html/.well-known/security.txt
sudo install -m 644 pgp-key.txt /var/www/example.com/html/.well-known/pgp-key.txt
ls -l /var/www/example.com/html/.well-known/Now the server block. If /etc/nginx/conf.d/example.com.conf already exists for your site, do not run the tee command below: it would replace your file, including the lines certbot added. Add only the two location blocks inside the existing listen 443 ssl server block instead, and leave its root line as it is. The full block below shows where they sit, for a server that has no configuration yet.
sudo tee /etc/nginx/conf.d/example.com.conf > /dev/null <<'CONF'
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /var/www/example.com/html;
# Serve /.well-known/ files as they are, with charset=utf-8 on text/plain.
# ^~ stops a "deny dotfiles" regex location elsewhere from blocking this path.
location ^~ /.well-known/ {
charset utf-8;
try_files $uri =404;
}
# Older tools look at the top level. The RFC allows a redirect.
location = /security.txt {
return 301 https://$host/.well-known/security.txt;
}
}
CONF
sudo nginx -tThe .txt extension already maps to text/plain in Nginx's mime.types. The charset utf-8; line adds ; charset=utf-8 to that type, because text/plain is in Nginx's default charset_types list. Many hardened configurations include a rule such as location ~ /\. { deny all; } to hide .git and .env files; without ^~, that rule would also hide .well-known.
Reload Nginx to apply the change:
sudo systemctl reload nginxCheck it worked
Ask for the headers:
curl -sI https://example.com/.well-known/security.txt
curl -sI https://example.com/.well-known/security.txt | grep -i '^content-type: text/plain; charset=utf-8'
curl -sI http://example.com/.well-known/security.txt | grep -i '^location:'
curl -sI https://example.com/security.txt | grep -i '^location:'The first response starts HTTP/1.1 200 OK and includes Content-Type: text/plain; charset=utf-8; the second command prints that line again. The plain HTTP request and the top-level /security.txt request both answer with a Location: pointing to https://example.com/.well-known/security.txt.
Step 6 · Write the disclosure policy
The Policy field links to this page. Keep it short and plain: the person reading it may be on a phone, on prepaid data, and reading in their second language. One small HTML page with no scripts loads anywhere. Edit the scope, the times and the names below to match what your team can really do. A promise to reply in three days that you then miss does more damage than a promise of ten days that you keep.
Have someone who can speak for your organisation, ideally with legal advice, approve the safe-harbour section before you publish it. It is a commitment not to pursue people who follow the rules.
sudo install -d -m 755 /var/www/example.com/html/security-policy
sudo tee /var/www/example.com/html/security-policy/index.html > /dev/null <<'HTML'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vulnerability disclosure policy</title>
</head>
<body>
<h1>Vulnerability disclosure policy</h1>
<p>Last updated: 2026-11-18. If you think you have found a security problem in our services, we want to hear from you.</p>
<h2 id="report">How to report</h2>
<p>Email <a href="mailto:security@example.com">security@example.com</a>. You may encrypt your report with our key at
<a href="https://example.com/.well-known/pgp-key.txt">/.well-known/pgp-key.txt</a>. We read reports in English and French.
Tell us what you found, where, the steps to reproduce it, and what an attacker could do with it.</p>
<h2 id="scope">Scope</h2>
<p>In scope: example.com, www.example.com and app.example.com.</p>
<p>Out of scope: services run for us by other companies (report those to the company), denial of service,
spam, social engineering of our staff, and physical access to our offices.</p>
<h2 id="rules">What we ask you not to do</h2>
<ul>
<li>Do not access, change or delete data that is not yours. Use test accounts; stop as soon as you see someone else's data.</li>
<li>Do not run tests that slow down or break the service for other people.</li>
<li>Do not use what you find for anything except confirming and reporting it.</li>
<li>Do not tell anyone else about the problem until we have fixed it or 90 days have passed, whichever is first, unless we agree otherwise.</li>
</ul>
<h2 id="safe-harbour">Safe harbour</h2>
<p>If you make a good-faith effort to follow this policy, we will consider your research authorised, we will not take
legal action against you or ask anyone else to, and if a third party does, we will make it known that you acted under this policy.</p>
<h2 id="response">What happens next</h2>
<ul>
<li>We confirm we have received your report within 3 working days.</li>
<li>We tell you whether we accept the problem, and how serious we think it is, within 10 working days.</li>
<li>We update you at least every 14 days until it is fixed, and tell you when it is.</li>
</ul>
<h2 id="credit">Credit</h2>
<p>With your permission, we name you on this page once the problem is fixed. We do not currently pay rewards.</p>
</body>
</html>
HTMLYou do not need to reload Nginx for new files; it serves whatever is in the web root.
Check it worked
curl -sI https://example.com/security-policy/ | grep -i '^content-type'
curl -s https://example.com/security-policy/ | grep -E 'Safe harbour|within 3 working days'The first command prints Content-Type: text/html. The second prints the Safe harbour heading and the acknowledgement line. Open https://example.com/security-policy/ on your phone: the page reads cleanly without zooming. Then open https://example.com/security-policy/#credit: the page scrolls to the Credit section, which is where the Acknowledgments field points.
Step 7 · Check the published file the way a researcher would
A finder, or a scanner, fetches the file, checks the signature and checks the date. Do the same, from the published copy rather than the one in your folder:
cd ~/security-txt-demo
curl -fsS https://example.com/.well-known/security.txt -o fetched.txt
gpg --verify fetched.txt 2>&1 | grep 'Good signature'
grep '^Canonical:' fetched.txtSomeone who does not have your key yet would import it first with curl -fsS https://example.com/.well-known/pgp-key.txt | gpg --import, and then compare the fingerprint with one you publish elsewhere, such as your company profile or a colleague's message.
Then write a small script that fails when the file is close to expiring, or has drifted more than a year out:
cd ~/security-txt-demo
cat > check-security-txt.sh <<'SH'
#!/usr/bin/env bash
# Warn when security.txt expires within 30 days, or is set more than a year ahead.
set -euo pipefail
url="${1:-https://example.com/.well-known/security.txt}"
expires=$(curl -fsS "$url" | sed -n 's/^Expires: //p')
days=$(( ( $(date -u -d "$expires" +%s) - $(date -u +%s) ) / 86400 ))
echo "security.txt at $url expires in $days days ($expires)"
if [ "$days" -lt 30 ] || [ "$days" -gt 366 ]; then
echo "Update Expires, sign the file again and republish it."
exit 1
fi
SH
chmod +x check-security-txt.sh
./check-security-txt.sh https://example.com/.well-known/security.txtCheck it worked
gpg --verify prints the Good signature line, the Canonical line shows the address you fetched from, and the script prints something like security.txt at https://example.com/.well-known/security.txt expires in 179 days (2027-05-25T09:14:02Z) and exits without the warning.
Step 8 · Keep it alive
A security.txt goes stale in two ways: the date runs out, or the mailbox stops being read. Put both on a schedule.
- Add a calendar reminder for 30 days before the
Expiresdate, owned by the team rather than one person. When it fires, change the date insecurity.txt.unsigned, run the--clearsigncommand, copy the file to the web root withsudo installas before, and run the check script. The key expires after a year too. Extend the primary key withgpg --quick-set-expire <fingerprint> 1y, then the encryption subkey withgpg --quick-set-expire <fingerprint> 1y '*'(replace<fingerprint>with yours; the first command alone leaves the subkey on its old date). Then export the key again and republishpgp-key.txt. - If you run a monitoring or CI job, add
check-security-txt.shto it, so a missed reminder still raises an alert. - Send a test report to the mailbox from an outside address every quarter, and time how long the first reply takes. Compare it with the times in your policy.
- When reports arrive, log them in your incident process, and use the same severity scale as your other findings.
Check it worked
Your team calendar has a reminder dated 30 days before the Expires value in the published file, and someone other than you has received and answered a test message to the security mailbox.
Next steps
- Turn incoming reports into prioritised work: /tutorials/triage-security-scanner-findings
- Decide what happens when a report turns out to be serious: /tutorials/write-an-incident-response-plan-for-a-small-team
- Send the right security headers from the same Nginx server: /tutorials/add-security-headers-in-nginx
- Serving with Caddy instead? The same files and rules apply: /tutorials/automatic-https-with-caddy-2
Related tutorials
- Write custom Fail2ban jails and filters for your own appsYou will have Fail2ban 1.1 banning repeated failed sign-ins to your own app and to an nginx basic-auth area, with filters you tested against sample logs, your own addresses allow-listed, and longer bans for repeat offenders.
- Validate file uploads before you store or serve themYou will take a FastAPI image upload route that trusts everything the browser sends, prove its flaws with pytest, and rebuild it with size limits, type checks from the file's own bytes, Pillow re-encoding, random storage names and safe download headers.
- Use SSH certificates instead of copying keys to every serverYou will run a small SSH certificate authority with ssh-keygen, log in to an Ubuntu 26.04 server with an eight-hour user certificate, give the server a host certificate so clients stop asking about fingerprints, and revoke a certificate the server then refuses.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials