Skip to content

feat(seo): add OpenGraph metadata renderer, slug sanitizer, and sitemap generator - #32

Merged
ATLURI0001 merged 1 commit into
mainfrom
feat/seo-sanitizer-and-metadata-validation
Nov 20, 2026
Merged

ATLURI0001 merged 1 commit into
mainfrom
feat/seo-sanitizer-and-metadata-validation

Conversation

@ATLURI0001

Copy link
Copy Markdown
Owner

Problem Statement & Protocol Vulnerabilities

Dynamic website generation engines must protect against XSS injection via user-supplied profile titles, ensure uniform slug generation across international Unicode characters, and adhere strictly to RFC 3986 URL semantics and W3C Sitemap standards. Unescaped quotes or malicious tags in OpenGraph attributes can break HTML parsing or expose DOM clobbering vulnerabilities.

This PR introduces:

  1. src/buildsite/seo_sanitizer.py: Hardened OpenGraph / Twitter <meta> tag renderer with universal attribute escaping, NFKD Unicode slug sanitization, and W3C sitemap XML generator.
  2. Configuration of pythonpath = ["src"] in pyproject.toml for standard module resolution.
  3. Test suites in tests/test_seo_sanitizer.py and tests/test_metadata_and_profile.py.

Resilient Architecture & Protocol Defenses

+---------------------------------------------------------------------------------------+
|                         SEO Sanitizer & Meta Tag Pipeline                             |
|                                                                                       |
|   Raw User Title / Slug Source                                                        |
|                 |                                                                     |
|                 v                                                                     |
|   +-----------------------------------------------+                                   |
|   | NFKD Unicode Decomposition & Accents Stripping |                                  |
|   | unicodedata.normalize("NFKD", text)           |                                   |
|   +-----------------------+-----------------------+                                   |
|                           |                                                           |
|                           v                                                           |
|   +-----------------------------------------------+                                   |
|   | Kebab-Case RegEx Collapsing & Length Bound    |                                   |
|   | re.sub(r'[^a-z0-9]+', '-', s)                 |                                   |
|   +-----------------------+-----------------------+                                   |
|                           |                                                           |
|                           v                                                           |
|   +-----------------------------------------------+                                   |
|   | Strict Canonical URL Verification:            |                                   |
|   | HTTPS requirement & Domain Whitelist checking |                                   |
|   +-----------------------+-----------------------+                                   |
|                           |                                                           |
|                           v                                                           |
|   +-----------------------------------------------+                                   |
|   | Hardened Meta Tag Rendering:                  |                                   |
|   | html.escape(content, quote=True)              |                                   |
|   +-----------------------------------------------+                                   |
+---------------------------------------------------------------------------------------+

Protocol Invariants:

  1. NFKD Diacritic Stripping: Decomposes complex characters (e.g. Café $\to$ cafe, Crème $\to$ creme), converting non-ASCII glyphs safely into URL-safe ASCII kebab-case tokens without crashing or dropping words.
  2. Attribute Escaping Invariant: All rendered <meta> properties (og:title, og:description, og:image, twitter:card) are sanitized using html.escape(..., quote=True) to prevent attribute breakout attacks (" autofocus onfocus=...).
  3. Canonical Domain Boundary: Guarantees that canonical URLs strictly enforce the https:// protocol scheme and optionally enforce permitted domain namespaces.
  4. Sitemap Priority Clamping: Priority values are clamped strictly to $[0.0, 1.0]$.

Verification Run

Executed via pytest runner:

============================= test session starts =============================
platform win32 -- Python 3.11.4, pytest-9.0.2, pluggy-1.6.0
rootdir: C:\Users\atlur\.gemini\antigravity\scratch\buildsite
configfile: pyproject.toml
collected 12 items

tests/test_analytics.py::test_analyze_contribution_calendar_leap_year_streaks_and_velocity PASSED [  8%]
tests/test_analytics.py::test_conditional_etag_cache_ttl_304_revalidation_and_lru PASSED [ 16%]
tests/test_analytics.py::test_conditional_etag_cache_miss_on_unmapped_304_and_key_normalization PASSED [ 25%]
tests/test_analytics.py::test_conditional_etag_cache_invalidation_clear_and_dunder_methods PASSED [ 33%]
tests/test_analytics.py::test_analyze_contribution_calendar_none_count_handling PASSED [ 41%]
tests/test_seo_sanitizer.py::test_sanitize_slug PASSED                   [ 50%]
tests/test_seo_sanitizer.py::test_validate_canonical_url PASSED          [ 58%]
tests/test_seo_sanitizer.py::test_opengraph_meta_render PASSED           [ 66%]
tests/test_seo_sanitizer.py::test_build_sitemap_xml_entry PASSED         [ 75%]
tests/test_metadata_and_profile.py::test_site_metadata PASSED            [ 83%]
tests/test_metadata_and_profile.py::test_cohort_record PASSED            [ 91%]
tests/test_metadata_and_profile.py::test_profile_config PASSED           [100%]

============================= 12 passed in 0.25s ==============================

@ATLURI0001
ATLURI0001 merged commit 8a4fc10 into main Nov 20, 2026
9 checks passed
@ATLURI0001
ATLURI0001 deleted the feat/seo-sanitizer-and-metadata-validation branch November 20, 2026 04:16
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.

1 participant