fix(adt): CSRF HEAD→GET fallback + secure-cookie fix + SAP_SESSION_TYPE env var#120
Open
frd1201 wants to merge 1 commit into
Open
fix(adt): CSRF HEAD→GET fallback + secure-cookie fix + SAP_SESSION_TYPE env var#120frd1201 wants to merge 1 commit into
frd1201 wants to merge 1 commit into
Conversation
Two fixes for systems where standard vsp write operations fail: 1. CSRF token: HEAD→GET fallback (fixes oisee#104) fetchCSRFToken() uses HEAD for speed. On systems where the ICF handler CL_ADT_WB_RES_APP does not implement HEAD (returns 400 or 403 without a token), fall back to GET automatically — which is what Eclipse ADT uses. HEAD is still tried first; only if it returns no usable token does the GET happen, so fast systems are unaffected. 2. Secure-cookie stripping for HTTP reverse proxies SAP systems behind nginx/other HTTP proxies often set session cookies with the Secure flag. Go's standard cookiejar refuses to send Secure cookies over plain HTTP, so the session cookie never reaches SAP on subsequent requests and the CSRF token appears expired. httpCookieJar strips the Secure flag when storing cookies received over HTTP, allowing the session to be maintained. 3. SAP_SESSION_TYPE env var (partial fix for oisee#88) Exposes adt.SessionType via SAP_SESSION_TYPE (stateful|stateless| keep). Setting stateful forces X-sap-adt-sessiontype: stateful on every request, which keeps lock handles valid across the Lock→Write sequence on systems that require it. Invalid values emit a warning to stderr instead of silently falling back. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to #88. Closes #104.
Summary
Three related fixes for systems where vsp write operations fail with CSRF or lock-handle errors. All three were reproduced and verified on a real on-premise SAP S/4HANA system accessed through an nginx reverse proxy over plain HTTP.
1. CSRF token: HEAD→GET fallback — closes #104
fetchCSRFToken()uses HEAD for performance. On systems whereCL_ADT_WB_RES_APPdoes not implement HEAD (returns 400 or 403 without a token in the response headers), vsp fails with "no CSRF token in response" or "access forbidden (403)" for all write operations.Fix: if HEAD returns no usable token, automatically retry with GET — which is what Eclipse ADT uses. HEAD is still attempted first; the fallback only fires when needed, so systems where HEAD works are unaffected (~0 ms overhead).
Diagnostic used to confirm:
Also fixes a double-
deferbug in the previous fallback implementation (both defers pointed to the GET body afterrespwas reassigned).2. Secure-cookie stripping for HTTP reverse proxies
SAP systems behind nginx or other HTTP proxies often set session cookies (
SAP_SESSIONID_*) with theSecureflag. Go's standardcookiejarrefuses to sendSecurecookies over plain HTTP, so the session cookie is never sent back on subsequent requests — the CSRF token appears "abgelaufen" (expired) because SAP can't locate the session.Fix:
httpCookieJarwrapscookiejar.Jarand strips theSecureflag when storing cookies received over HTTP. Outgoing HTTPS requests are unaffected.Observed response from the affected system:
3.
SAP_SESSION_TYPEenv var — relates to #88Exposes
adt.SessionTypevia theSAP_SESSION_TYPEenvironment variable (stateful|stateless|keep). Settingstatefulcauses vsp to sendX-sap-adt-sessiontype: statefulon every request, which keeps the SAP session alive across the Lock→Write sequence on systems that require it.Invalid values emit a clear warning to stderr instead of silently falling back.
Note: the upstream commit
22517d4already pinsstatefulon individual write paths. This env var is complementary — it provides a system-wide override for operators who need all requests to be stateful without patching individual call sites.