Skip to content

Commit 50ffcd2

Browse files
waleedlatif1claude
andcommitted
fix(sap_s4hana): ignore baseUrl on cloud_public to prevent token redirection
Why: resolveHost previously preferred baseUrl unconditionally. A caller sending deploymentType=cloud_public with a baseUrl pointing elsewhere would obtain a real SAP UAA token, then forward it as Bearer to the attacker host. Zod superRefine did not validate baseUrl for cloud_public. Fix: resolveHost now constructs the SAP host from subdomain when deploymentType is cloud_public and only uses baseUrl for cloud_private and on_premise (where it is already SSRF-checked in superRefine). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a922104 commit 50ffcd2

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • apps/sim/app/api/tools/sap_s4hana/proxy

apps/sim/app/api/tools/sap_s4hana/proxy/route.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,15 @@ async function fetchCsrf(
399399
}
400400

401401
function resolveHost(req: ProxyRequest): string {
402-
if (req.baseUrl) {
403-
const trimmed = req.baseUrl.replace(/\/+$/, '')
404-
return assertSafeExternalUrl(trimmed, 'baseUrl').toString().replace(/\/+$/, '')
402+
if (req.deploymentType === 'cloud_public') {
403+
const constructed = `https://${req.subdomain}-api.s4hana.ondemand.com`
404+
return assertSafeExternalUrl(constructed, 'subdomain').toString().replace(/\/+$/, '')
405405
}
406-
const constructed = `https://${req.subdomain}-api.s4hana.ondemand.com`
407-
return assertSafeExternalUrl(constructed, 'subdomain').toString().replace(/\/+$/, '')
406+
if (!req.baseUrl) {
407+
throw new Error('baseUrl is required for cloud_private and on_premise deployments')
408+
}
409+
const trimmed = req.baseUrl.replace(/\/+$/, '')
410+
return assertSafeExternalUrl(trimmed, 'baseUrl').toString().replace(/\/+$/, '')
408411
}
409412

410413
function buildOdataUrl(req: ProxyRequest, pathOverride?: string): string {

0 commit comments

Comments
 (0)