Skip to content

Commit cf2d83e

Browse files
waleedlatif1claude
andcommitted
fix(sap_s4hana): scope CSRF metadata fetch and isolate token cache by secret
- buildOdataUrl skips request query params when called with an internal pathOverride so the /$metadata CSRF probe never carries user OData options ($filter, $top, $select), which were causing write operations through the generic odata_query tool to fail. - tokenCacheKey now mixes a sha256 hash of clientSecret into the cache key so two tenants sharing the same tokenUrl + clientId but different secrets get isolated entries (no cross-tenant token leak). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent ff6b4c2 commit cf2d83e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createHash } from 'node:crypto'
12
import { createLogger } from '@sim/logger'
23
import { toError } from '@sim/utils/errors'
34
import { type NextRequest, NextResponse } from 'next/server'
@@ -277,7 +278,10 @@ function resolveTokenUrl(req: ProxyRequest): string {
277278
}
278279

279280
function tokenCacheKey(req: ProxyRequest): string {
280-
return `${resolveTokenUrl(req)}::${req.clientId ?? ''}`
281+
const secretHash = req.clientSecret
282+
? createHash('sha256').update(req.clientSecret).digest('hex').slice(0, 16)
283+
: ''
284+
return `${resolveTokenUrl(req)}::${req.clientId ?? ''}::${secretHash}`
281285
}
282286

283287
function rememberToken(key: string, token: CachedToken): void {
@@ -402,6 +406,9 @@ function buildOdataUrl(req: ProxyRequest, pathOverride?: string): string {
402406
const normalized = subPath.startsWith('/') ? subPath : `/${subPath}`
403407
const base = `${host}${servicePath}${normalized}`
404408

409+
if (pathOverride !== undefined) {
410+
return base
411+
}
405412
if (!req.query || Object.keys(req.query).length === 0) {
406413
return base
407414
}

0 commit comments

Comments
 (0)