Deploy on DigitalOcean App Platform (GitHub-source build) + consolidate audit-fixes
Deploy config: - .do/app.yaml: build the Dockerfile directly from GitHub (deploy_on_push) instead of a pre-built DOCR image; NEXT_PUBLIC_* set RUN_AND_BUILD_TIME with the propertymanagement.network domain so they bake into the client bundle; add custom domains block (apex + www); wire Sentry DSN (server + browser). Included pending work from the audit-fixes branch: - AI provider abstraction (OpenAI/Anthropic, admin-selectable; Anthropic default) - Per-landlord e-signature (DocuSign OAuth + Dropbox Sign) + migration 0010 - Outbound webhooks / Zapier integration - PayPal removal (Stripe-only billing) - Storage hardening (fail-loud when Spaces unconfigured), security fixes Verified: full production Docker build (same build-args as DO) passes clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
917a06ee85
commit
5495b94924
@@ -0,0 +1,48 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { cookies } from "next/headers"
|
||||
import { getSessionUser } from "@/lib/session"
|
||||
import { getAccountContext } from "@/lib/account"
|
||||
import { getAdapter, saveEsignConnection, type ESignProvider } from "@/lib/esign"
|
||||
import { verifyState, ESIGN_NONCE_COOKIE } from "@/lib/esign/state"
|
||||
|
||||
// OAuth callback — exchanges the code for tokens and stores the connection.
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ provider: string }> }) {
|
||||
const { provider } = await params
|
||||
const adapter = getAdapter(provider)
|
||||
const settings = new URL("/settings/integrations", request.url)
|
||||
|
||||
const cookieStore = await cookies()
|
||||
const nonceCookie = cookieStore.get(ESIGN_NONCE_COOKIE)?.value
|
||||
const done = (p: Record<string, string>) => {
|
||||
for (const [k, v] of Object.entries(p)) settings.searchParams.set(k, v)
|
||||
const res = NextResponse.redirect(settings)
|
||||
res.cookies.set(ESIGN_NONCE_COOKIE, "", { path: "/", maxAge: 0 })
|
||||
return res
|
||||
}
|
||||
|
||||
const url = new URL(request.url)
|
||||
const code = url.searchParams.get("code")
|
||||
const state = url.searchParams.get("state")
|
||||
const oauthError = url.searchParams.get("error")
|
||||
|
||||
if (oauthError || !adapter || adapter.kind !== "oauth") return done({ error: "connect_failed" })
|
||||
|
||||
const st = state ? verifyState(state) : null
|
||||
// CSRF: state nonce must match the cookie, and the session must be the same owner.
|
||||
if (!code || !st || st.provider !== provider || !nonceCookie || nonceCookie !== st.nonce) {
|
||||
return done({ error: "invalid_state" })
|
||||
}
|
||||
const user = await getSessionUser()
|
||||
if (!user) return done({ error: "invalid_state" })
|
||||
const ctx = await getAccountContext(user.id)
|
||||
if (ctx.ownerId !== st.ownerId) return done({ error: "invalid_state" })
|
||||
|
||||
try {
|
||||
const tokens = await adapter.exchangeCode(code)
|
||||
if (!tokens.accountId || !tokens.baseUri) throw new Error("No account returned from provider")
|
||||
await saveEsignConnection(st.ownerId, provider as ESignProvider, tokens)
|
||||
return done({ connected: provider })
|
||||
} catch {
|
||||
return done({ error: "connect_failed" })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import crypto from "crypto"
|
||||
import { NextResponse } from "next/server"
|
||||
import { getSessionUser } from "@/lib/session"
|
||||
import { getAccountContext } from "@/lib/account"
|
||||
import { getAdapter } from "@/lib/esign"
|
||||
import { signState, ESIGN_NONCE_COOKIE } from "@/lib/esign/state"
|
||||
|
||||
// Starts the OAuth connect flow for an e-signature provider (owner-only).
|
||||
// API-key providers (Dropbox Sign) don't use this — they connect via a form.
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ provider: string }> }) {
|
||||
const { provider } = await params
|
||||
const adapter = getAdapter(provider)
|
||||
const settings = new URL("/settings/integrations", request.url)
|
||||
|
||||
if (!adapter) {
|
||||
settings.searchParams.set("error", "unknown_provider")
|
||||
return NextResponse.redirect(settings)
|
||||
}
|
||||
|
||||
const user = await getSessionUser()
|
||||
if (!user) return NextResponse.redirect(new URL("/login", request.url))
|
||||
|
||||
const ctx = await getAccountContext(user.id)
|
||||
if (!ctx.isOwner) {
|
||||
settings.searchParams.set("error", "owner_only")
|
||||
return NextResponse.redirect(settings)
|
||||
}
|
||||
if (adapter.kind !== "oauth") {
|
||||
settings.searchParams.set("error", "use_api_key")
|
||||
return NextResponse.redirect(settings)
|
||||
}
|
||||
if (!adapter.available()) {
|
||||
settings.searchParams.set("error", "not_configured")
|
||||
return NextResponse.redirect(settings)
|
||||
}
|
||||
|
||||
// Bind the round-trip to this browser: nonce in the signed state AND a cookie.
|
||||
const nonce = crypto.randomUUID()
|
||||
const state = signState({ ownerId: ctx.ownerId, provider, nonce })
|
||||
const res = NextResponse.redirect(adapter.getAuthUrl(state))
|
||||
res.cookies.set(ESIGN_NONCE_COOKIE, nonce, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
maxAge: 600,
|
||||
})
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user