-
Notifications
You must be signed in to change notification settings - Fork 248
DRIVERS-3568 Define PSL support in the Initial DNS Seedlist Discovery Specification #1972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
64f96ba
2d22775
ce7d02e
bc2bc4b
f4a4d19
b741042
8d448d0
31e048a
997cdc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| name: Sync Public Suffix List | ||
|
|
||
| on: | ||
| schedule: | ||
| # 12:00 UTC on the first day of each month. | ||
| - cron: "0 12 1 * *" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| env: | ||
| PSL: source/public-suffix-list/public_suffix_list.dat | ||
|
|
||
| jobs: | ||
| sync: | ||
| name: Sync PSL and open a PR | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semgrep identified an issue in your code:
More details about this
A plausible attack looks like this:
To resolve this comment: ✨ Commit fix suggestion
Alternatively, if you need an easier update path, use Dependabot or Renovate to keep pinned GitHub Action SHAs updated automatically while still keeping 💬 Ignore this findingReply with Semgrep commands to ignore this finding.
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by github-actions-mutable-action-tag. 🛟 Help? Slack #semgrep-help or go/semgrep-help. Resolution Options:
You can view more details about this finding in the Semgrep AppSec Platform. |
||
| - name: Sync the Public Suffix List | ||
| run: python3 source/public-suffix-list/etc/sync-psl.py | ||
| - name: Check whether the list changed | ||
| id: changed | ||
| run: | | ||
| if git diff --quiet -- "$PSL"; then | ||
| echo "The list is unchanged; nothing to do." | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| - name: Commit and push | ||
| id: push | ||
| if: steps.changed.outputs.changed == 'true' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| # Each run gets its own branch, so nothing is ever force-pushed over. A run that | ||
| # collides with an earlier branch from the same day is rejected rather than | ||
| # overwriting it. | ||
| today=$(date -u +%Y-%m-%d) | ||
| branch="sync-psl-$today" | ||
| git switch -c "$branch" | ||
| git add -- "$PSL" | ||
| git commit -m "[$today] Sync the Public Suffix List" | ||
| git push origin "$branch" | ||
| echo "branch=$branch" >> "$GITHUB_OUTPUT" | ||
| echo "today=$today" >> "$GITHUB_OUTPUT" | ||
| - name: Open a pull request | ||
| if: steps.changed.outputs.changed == 'true' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| BRANCH: ${{ steps.push.outputs.branch }} | ||
| TODAY: ${{ steps.push.outputs.today }} | ||
| run: | | ||
| body=$(cat <<'EOF' | ||
| The upstream [Public Suffix List](https://publicsuffix.org/list/) has changed. | ||
|
|
||
| This pull request was opened automatically by the `sync-psl` workflow, which regenerates | ||
| `source/public-suffix-list/public_suffix_list.dat` via `source/public-suffix-list/etc/sync-psl.py`. | ||
|
|
||
| Please review the diff before merging. If an earlier sync pull request is still open, | ||
| merge or close this one and that one together -- they change the same file. | ||
|
Comment on lines
+65
to
+66
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what this PR note is trying to convey. Should reviewers close all PSL update PRs except for the latest? Or merge all PSL update PRs in a specific order? |
||
| EOF | ||
| ) | ||
| gh pr create \ | ||
| --base master \ | ||
| --head "$BRANCH" \ | ||
| --title "[$TODAY] Sync the Public Suffix List" \ | ||
| --body "$body" | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # "10gen.cc" is not in the Public Suffix List -- only its parent "cc" is -- so it is | ||
| # not a public suffix and must be accepted. The SRV hosts end with it, so resolution | ||
| # succeeds. | ||
| uri: "mongodb+srv://test1.test.build.10gen.cc/?srvAllowedHostsSuffix=10gen.cc" | ||
| seeds: | ||
| - localhost.test.build.10gen.cc:27017 | ||
| - localhost.test.build.10gen.cc:27018 | ||
| hosts: | ||
| - localhost:27017 | ||
| - localhost:27018 | ||
| - localhost:27019 | ||
| options: | ||
| ssl: true | ||
| srvAllowedHostsSuffix: "10gen.cc" | ||
| ping: true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # "cc" is an ordinary rule in the Public Suffix List, so it is itself a public suffix | ||
| # and must be rejected. The SRV hosts do end with "cc", so the host suffix check | ||
| # passes and the public suffix check is the only thing that can fail here. | ||
| uri: "mongodb+srv://test1.test.build.10gen.cc/?srvAllowedHostsSuffix=cc" | ||
| seeds: [] | ||
| hosts: [] | ||
| error: true |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||||
| """Sync the Public Suffix List from publicsuffix.org into this specification. | ||||||||||
|
|
||||||||||
| Usage: | ||||||||||
|
|
||||||||||
| python source/public-suffix-list/etc/sync-psl.py [--check] | ||||||||||
|
|
||||||||||
| Downloads the upstream list, strips comment and blank lines, and writes the result | ||||||||||
| to source/public-suffix-list/public_suffix_list.dat. With --check, does not write | ||||||||||
| anything and exits non-zero if the committed file is out of date. | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| import argparse | ||||||||||
| import sys | ||||||||||
| import urllib.request | ||||||||||
| from pathlib import Path | ||||||||||
|
|
||||||||||
| PSL_URL = "https://publicsuffix.org/list/public_suffix_list.dat" | ||||||||||
|
|
||||||||||
| # source/public-suffix-list/etc/sync-psl.py -> source/public-suffix-list | ||||||||||
| SPEC_DIR = Path(__file__).resolve().parent.parent | ||||||||||
| DEST = SPEC_DIR / "public_suffix_list.dat" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def fetch(): | ||||||||||
| request = urllib.request.Request(PSL_URL, headers={"User-Agent": "mongodb-specifications-sync-psl"}) | ||||||||||
| with urllib.request.urlopen(request) as response: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional:
Suggested change
|
||||||||||
| data = response.read() | ||||||||||
|
|
||||||||||
| text = data.decode("utf-8") | ||||||||||
|
|
||||||||||
| # Sanity check: the upstream file always carries these section markers. | ||||||||||
| for marker in ("// ===END ICANN DOMAINS===", "// ===END PRIVATE DOMAINS==="): | ||||||||||
| if marker not in text: | ||||||||||
| sys.exit(f"Downloaded file is missing expected markers {marker!r}; refusing to write.") | ||||||||||
|
|
||||||||||
| return text | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def preprocess(text): | ||||||||||
| """Reduce the upstream list to one rule per line. | ||||||||||
|
|
||||||||||
| Comment lines (those beginning with "//") and blank lines are both removed, so | ||||||||||
| every line will be a rule. | ||||||||||
| """ | ||||||||||
| rules = [] | ||||||||||
| for line in text.splitlines(): | ||||||||||
| # Upstream rules are not indented, but strip anyway so a stray trailing \r or | ||||||||||
| # space does not end up inside a rule. | ||||||||||
| line = line.strip() | ||||||||||
| if not line or line.startswith("//"): | ||||||||||
| continue | ||||||||||
| rules.append(line) | ||||||||||
|
|
||||||||||
| if not rules: | ||||||||||
| sys.exit("No rules found after stripping comments; refusing to write.") | ||||||||||
|
|
||||||||||
| # End the file with exactly one newline. | ||||||||||
| return "\n".join(rules) + "\n" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def main(): | ||||||||||
| parser = argparse.ArgumentParser(description=__doc__) | ||||||||||
| parser.add_argument( | ||||||||||
| "--check", | ||||||||||
| action="store_true", | ||||||||||
| help="exit non-zero if the committed list differs from upstream, without writing", | ||||||||||
| ) | ||||||||||
| args = parser.parse_args() | ||||||||||
|
|
||||||||||
| new_text = preprocess(fetch()) | ||||||||||
|
|
||||||||||
| old_text = DEST.read_text(encoding="utf-8") if DEST.exists() else None | ||||||||||
|
|
||||||||||
| if args.check: | ||||||||||
| if old_text is None: | ||||||||||
| sys.exit(f"{DEST} does not exist; run this script without --check.") | ||||||||||
| if old_text != new_text: | ||||||||||
| sys.exit(f"{DEST} is out of date; run source/public-suffix-list/etc/sync-psl.py.") | ||||||||||
| print(f"{DEST.name} is up to date.") | ||||||||||
| return | ||||||||||
|
|
||||||||||
| if old_text == new_text: | ||||||||||
| print(f"{DEST.name} is already up to date ({len(new_text.splitlines())} lines).") | ||||||||||
| return | ||||||||||
|
|
||||||||||
| DEST.write_text(new_text, encoding="utf-8") | ||||||||||
| print(f"Wrote {DEST} ({len(new_text.splitlines())} lines).") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| if __name__ == "__main__": | ||||||||||
| main() | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Require these permissions only for the "Commit and push" and "Open a pull request" steps.