Refactor research URL handling and add trusted URL validation

AH
5mo ago
+190-9
  • Updated getResearchUrlsHandler to utilize formatResearchUrlsResponse for improved URL formatting.
  • Enhanced normalizeUrlMap to use isTrustedResearchUrl for validating URLs, ensuring only trusted links are processed.
  • Added a new test case in fetchSongstatsResearch.test.ts to verify that only trusted HTTPS links are mapped from artist URLs, improving data integrity and security.

Summary by cubic

Enforces HTTPS-only, credential-free research URLs and centralizes response formatting for a safer, consistent GET /api/research/urls. Drops untrusted links and prefers the first trusted url/link/href when multiple exist.

  • Refactors
    • Added isTrustedResearchUrl and pickTrustedResearchUrl (with RESEARCH_LINK_KEYS) to allow only HTTPS URLs without credentials.
    • Updated normalizeUrlMap to use pickTrustedResearchUrl, trust-check bare strings, and skip link keys once selected.
    • Switched getResearchUrlsHandler to formatResearchUrlsResponse; added tests for trust checks, selection order, response formatting, and Songstats mapping.

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened URL validation for research data to enforce HTTPS-only protocol and reject URLs with embedded credentials
    • Improved filtering of research URLs to ensure only valid, trusted domains are included in results