@simplelayer/graniteer-core 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,43 @@ const corsHeaders = {
22
22
  'Access-Control-Allow-Origin': '*',
23
23
  'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-lovable-signature, x-lovable-timestamp, x-supabase-client-platform, x-supabase-client-platform-version, x-supabase-client-runtime, x-supabase-client-runtime-version',
24
24
  };
25
+ // `data.url` for magiclink (and recovery) arrives as Supabase's own
26
+ // `{SUPABASE_URL}/auth/v1/verify?token=<hash>&type=<type>&redirect_to=<dest>`
27
+ // action link. That link performs the OTP verification on a plain GET, so an
28
+ // email-scanner prefetch (M365 Safe Links, etc.) silently burns the token
29
+ // before the real recipient ever clicks -- confirmed live 2026-09-23 against
30
+ // kyle+qatest@simplelayer.io (M365-hosted inbox): the link arrived, was
31
+ // pre-fetched, and the user's own click then hit an already-consumed token
32
+ // (otp_expired).
33
+ //
34
+ // Fix (magiclink only, for now): rewrite the emailed link to point at our own
35
+ // /portal/confirm page instead, carrying the same token/type/redirect_to as
36
+ // query params. That page does nothing on load -- it renders a "Continue to
37
+ // sign in" button and only calls supabase.auth.verifyOtp({token_hash, type})
38
+ // on an actual click, so a scanner's GET can no longer consume the token.
39
+ //
40
+ // Fails open: if the URL doesn't parse or is missing an expected param
41
+ // (Supabase changes the link shape, a non-magiclink call site reuses this),
42
+ // return the original link unchanged rather than break the login/reset flow.
43
+ function toClickToContinueUrl(rawUrl) {
44
+ try {
45
+ const u = new URL(rawUrl);
46
+ const token = u.searchParams.get('token');
47
+ const type = u.searchParams.get('type');
48
+ const redirectTo = u.searchParams.get('redirect_to');
49
+ if (!token || !type || !redirectTo)
50
+ return rawUrl;
51
+ const dest = new URL(redirectTo);
52
+ const confirm = new URL('/portal/confirm', dest.origin);
53
+ confirm.searchParams.set('token_hash', token);
54
+ confirm.searchParams.set('type', type);
55
+ confirm.searchParams.set('redirect_to', redirectTo);
56
+ return confirm.toString();
57
+ }
58
+ catch {
59
+ return rawUrl;
60
+ }
61
+ }
25
62
  // Template mapping for preview mode
26
63
  const EMAIL_TEMPLATES = {
27
64
  signup: SignupEmail,
@@ -164,7 +201,10 @@ export function createAuthEmailHook(config) {
164
201
  subject: 'Your login link',
165
202
  render: (data) => React.createElement(MagicLinkEmail, {
166
203
  siteName: SITE_NAME,
167
- confirmationUrl: data.url,
204
+ // Click-to-continue (2026-09-23): route through our own confirm
205
+ // page instead of Supabase's direct, scanner-vulnerable /verify
206
+ // GET link. See toClickToContinueUrl() above.
207
+ confirmationUrl: toClickToContinueUrl(data.url),
168
208
  colors: BRAND_COLORS,
169
209
  footerLine: FOOTER_LINE,
170
210
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplelayer/graniteer-core",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Shared platform core for Graniteer",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",