Skip to content

Commit cd2fdf7

Browse files
waleedlatif1claude
andcommitted
fix(sap_s4hana): reject percent-encoded path traversal; widen Set-Cookie split
- ServicePath now also rejects %2e/%2E, %2f/%2F, %5c/%5C, %3f/%3F, %23 so a caller cannot smuggle ".." / "." / "/" / "\" / "?" / "#" past the validator and have SAP's ABAP/ICM gateway decode them server-side. - joinSetCookies fallback regex now allows the ", " separator that's used when multiple Set-Cookie values are folded onto one header line (older runtimes without Headers.getSetCookie). Prevents CSRF cookies from being concatenated into a single value during write operations. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 04a3986 commit cd2fdf7

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

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

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ const ServicePath = z
3030
(p) =>
3131
!p.split(/[/\\]/).some((seg) => seg === '..' || seg === '.') &&
3232
!p.includes('?') &&
33-
!p.includes('#'),
33+
!p.includes('#') &&
34+
!/%(?:2[eEfF]|5[cC]|3[fF]|23)/.test(p),
3435
{
35-
message: 'path must not contain ".." or "." segments, "?", or "#"',
36+
message:
37+
'path must not contain ".." or "." segments, "?", "#", or percent-encoded path/query/fragment characters',
3638
}
3739
)
3840

@@ -353,7 +355,7 @@ function joinSetCookies(headers: Headers): string {
353355
const cookies =
354356
typeof (headers as { getSetCookie?: () => string[] }).getSetCookie === 'function'
355357
? (headers as { getSetCookie: () => string[] }).getSetCookie()
356-
: (headers.get('set-cookie') ?? '').split(/,(?=[^ ;]+=)/)
358+
: (headers.get('set-cookie') ?? '').split(/,\s*(?=[^=,;\s]+=)/)
357359
return cookies
358360
.map((c) => c.split(';')[0]?.trim())
359361
.filter(Boolean)

0 commit comments

Comments
 (0)