Refactor research URL handling and add trusted URL validation
AH
5mo ago+190+190+012345678901234567890123456789-9-9-0123456789
- Updated
getResearchUrlsHandlerto utilizeformatResearchUrlsResponsefor improved URL formatting. - Enhanced
normalizeUrlMapto useisTrustedResearchUrlfor validating URLs, ensuring only trusted links are processed. - Added a new test case in
fetchSongstatsResearch.test.tsto 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
isTrustedResearchUrlandpickTrustedResearchUrl(withRESEARCH_LINK_KEYS) to allow only HTTPS URLs without credentials. - Updated
normalizeUrlMapto usepickTrustedResearchUrl, trust-check bare strings, and skip link keys once selected. - Switched
getResearchUrlsHandlertoformatResearchUrlsResponse; added tests for trust checks, selection order, response formatting, and Songstats mapping.
- Added
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