Skip to content

Main - #33

Merged
timothylee58 merged 6 commits into
masterfrom
main
Aug 3, 2026
Merged

Main#33
timothylee58 merged 6 commits into
masterfrom
main

Conversation

@timothylee58

@timothylee58 timothylee58 commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Note

Medium Risk
Touches API key exposure rules and security headers; behavior is tightened to hostname equality but still gates on Origin/Referer when BASE_URL is set.

Overview
Fixes Google Maps failing to load when the app fetches GET /api/gmaps/key: Helmet’s default no-referrer stripped Referer, so the same-origin guard always returned 403 even from the real site. Sets referrerPolicy: strict-origin-when-cross-origin so same-origin requests still send a usable Referer.

Same-origin validation on getGoogleMapsKey no longer uses string prefix checks on BASE_URL. It compares hostnames via a new toHostname() helper (missing https://, trailing slashes, Origin vs full Referer URLs). The client now surfaces HTTP status and API error text when key fetch fails.

Adds Jest coverage for 503/403/200 paths and the misconfiguration cases above.

Reviewed by Cursor Bugbot for commit 1b9bd3c. Configure here.

Summary by cubic

Fixes 403s when loading Google Maps by making the /api/gmaps/key same-origin check robust and keeping the Referer header. Also surfaces real errors on the frontend and adds tests to prevent regressions.

  • Bug Fixes
    • Compare hostnames for Origin/Referer vs BASE_URL, tolerating scheme-less BASE_URL and trailing slashes; fallback to Referer when Origin is missing.
    • Set helmet referrerPolicy to strict-origin-when-cross-origin so same-origin fetches send a Referer.
    • Frontend now checks response.ok/status and shows the actual error (e.g., 403/503) when the key request fails.
    • Added unit tests for getGoogleMapsKey covering no key, dev mode, matching origin, scheme-less BASE_URL, Referer fallback, trailing slash, and 403 cases.

Written for commit 1b9bd3c. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved same-origin validation for map-related requests, including URLs with different schemes, trailing slashes, or missing schemes.
    • Map loading errors now display the server’s specific error message and HTTP status.
    • Added clearer referrer information for cross-origin requests.
  • Tests

    • Added comprehensive coverage for API key authorization and invalid request scenarios.

claude and others added 6 commits August 2, 2026 15:10
The Origin/Referer check previously used raw string prefix matching
against BASE_URL, so a BASE_URL set without a scheme (e.g.
'example.up.railway.app' instead of 'https://example.up.railway.app')
would never match a browser's 'https://example.up.railway.app' Origin
header, causing every request to 403 — this is exactly what happened
on the live Railway deployment.

Now parses both BASE_URL and the incoming Origin/Referer into
hostnames via the URL constructor (defaulting to https:// when no
scheme is present) and compares hostnames instead of raw strings, so
scheme mismatches and trailing slashes no longer break the check.

Added backend/__tests__/controllers/weatherProxyController.test.js
covering: no key configured, no BASE_URL (dev mode), matching origin,
scheme-less BASE_URL, Referer fallback, trailing slash, and 403 cases.
Make /api/gmaps/key origin check tolerant of scheme-less BASE_URL
fetch() never rejects on non-2xx status, so 'r.json()' on a 403
(Forbidden — origin mismatch) or 503 (key not configured) response
silently parsed the error body without checking r.ok. The catch
block then always logged the same generic 'No Google Maps API key
returned' regardless of the real cause, making it impossible to
diagnose from the browser console alone.

Now checks r.ok/r.status and surfaces the actual error message and
HTTP status in both the console error and the on-page banner.
Surface real /api/gmaps/key error status on the frontend
Helmet defaults to 'Referrer-Policy: no-referrer', which strips the
Referer header from every outgoing request the page makes — including
the same-origin fetch('/api/gmaps/key') call. Combined with browsers
not reliably sending an Origin header on simple same-origin GET fetches,
the backend's same-origin check in weatherProxyController.js always had
nothing to compare against, so it 403'd unconditionally — even from the
real page, regardless of BASE_URL correctness.

Set referrerPolicy to 'strict-origin-when-cross-origin' (the browser's
own default absent any CSP framework), which sends the full Referer on
same-origin requests while still only sending the bare origin
cross-origin. Verified locally: a same-origin Referer now correctly
authorizes the request, while no Referer/Origin still correctly 403s.
Fix Helmet's default no-referrer policy breaking /api/gmaps/key
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@timothylee58
timothylee58 merged commit ab47340 into master Aug 3, 2026
2 of 4 checks passed
@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_e0d59c72-0694-4d2e-8021-22dd5760d666)

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 13f1baec-6076-4b74-a8ae-5a9fad6b766e

📥 Commits

Reviewing files that changed from the base of the PR and between 42cb6fc and 1b9bd3c.

📒 Files selected for processing (4)
  • backend/__tests__/controllers/weatherProxyController.test.js
  • backend/app.js
  • backend/controllers/weatherProxyController.js
  • backend/public/app.js

📝 Walkthrough

Walkthrough

Changes

Google Maps key flow

Layer / File(s) Summary
Backend validation and referrer policy
backend/controllers/weatherProxyController.js, backend/app.js, backend/__tests__/controllers/weatherProxyController.test.js
Hostname normalization now supports optional schemes and case-insensitive comparison for BASE_URL, Origin, and Referer. Helmet uses strict-origin-when-cross-origin. Jest tests cover authorized, unauthorized, and missing-key responses.
Frontend key-loading errors
backend/public/app.js
Google Maps key loading now preserves HTTP status and server error details. The map-load error displays the returned message.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: claude

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch main

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.

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.

2 participants