Skip to content

fix: canonicalize Last.fm connect URL host in production - #195

Merged
LucasSantana-Dev merged 1 commit into
mainfrom
fix/lastfm-canonical-prod-url
Mar 13, 2026
Merged

LucasSantana-Dev merged 1 commit into
mainfrom
fix/lastfm-canonical-prod-url

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Mar 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • harden /lastfm link URL origin validation to accept only HTTP(S)
  • reject legacy nexus.lucassantana.tech origins in link generation
  • add regression tests for stale/invalid origin fallbacks
  • document canonical production contract for WEBAPP_BACKEND_URL and WEBAPP_REDIRECT_URI

Verification

  • npm run test --workspace=packages/bot -- packages/bot/src/functions/general/commands/lastfm.spec.ts
  • npm run test --workspace=packages/bot -- lastfm
  • npm run type:check --workspace=packages/bot

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Last.fm link generation to reject invalid and legacy origins, preventing malformed URLs from appearing in production environments.
  • Documentation

    • Updated OAuth origin fallback behavior documentation and environment variable descriptions for improved clarity on production URL requirements.

@vercel

vercel Bot commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment Mar 13, 2026 3:43am

Request Review

@netlify

netlify Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for regal-bunny-0c8efe ready!

Name Link
🔨 Latest commit 3dc0307
🔍 Latest deploy log https://app.netlify.com/projects/regal-bunny-0c8efe/deploys/69b387e57572030008f66e83
😎 Deploy Preview https://deploy-preview-195--regal-bunny-0c8efe.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Mar 13, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This change adds validation to the Last.fm link origin-resolution logic, rejecting legacy nexus.lucassantana.tech and non-HTTP(S) URLs while falling back to WEBAPP_REDIRECT_URI when appropriate, alongside documentation clarifications and comprehensive test coverage.

Changes

Cohort / File(s) Summary
Documentation Updates
CHANGELOG.md, README.md
Clarified origin rejection behavior for legacy nexus and non-HTTP(S) origins during connect URL generation. Expanded environment variable descriptions for WEBAPP_REDIRECT_URI and WEBAPP_BACKEND_URL to document canonical production URL requirements.
Core Implementation
packages/bot/src/functions/general/commands/lastfm.ts
Updated getAbsoluteOrigin function to validate protocol (http/https only) and reject legacy nexus.lucassantana.tech hostname before returning origin, preventing invalid origins in production embeds.
Test Coverage
packages/bot/src/functions/general/commands/lastfm.spec.ts
Added tests verifying fallback behavior when backend URL is legacy or invalid, configuration errors when both URLs are invalid, and normalization behavior with invalid origins excluded.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Bot as Bot Command Handler
    participant Validator as getAbsoluteOrigin()
    participant Backend as WEBAPP_BACKEND_URL
    participant Redirect as WEBAPP_REDIRECT_URI

    Client->>Bot: Request Last.fm connect link
    Bot->>Validator: Validate WEBAPP_BACKEND_URL
    Validator->>Backend: Parse and check protocol & hostname
    alt Valid (http/https & not nexus)
        Validator-->>Bot: Return backend origin
    else Invalid
        Validator-->>Bot: Return null
        Bot->>Validator: Validate WEBAPP_REDIRECT_URI
        Validator->>Redirect: Parse and check protocol & hostname
        alt Valid (http/https & not nexus)
            Validator-->>Bot: Return redirect origin
        else Invalid
            Validator-->>Bot: Return null (config error)
        end
    end
    Bot-->>Client: Connect URL or error embed
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

bot, size/s

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: hardening URL origin validation and rejecting legacy nexus origins for Last.fm connect URL generation in production.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/lastfm-canonical-prod-url
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
54.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@coderabbitai coderabbitai Bot added the size/s label Mar 13, 2026
@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit e8e160a into main Mar 13, 2026
14 of 15 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/lastfm-canonical-prod-url branch March 13, 2026 03:54

This branch was successfully deployed

1 active deployment
Preview — 3dc0307e Deployed Mar 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant