Skip to content

fix(sap_concur): HMAC the token cache key and wire the sendback comment - #6794

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/concur-hmac-and-sendback
Aug 18, 2026
Merged

fix(sap_concur): HMAC the token cache key and wire the sendback comment#6794
waleedlatif1 merged 3 commits into
stagingfrom
fix/concur-hmac-and-sendback

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #6790 — these two commits were pushed to that branch after it had already been merged, so they never landed. Cherry-picked onto current staging, unchanged.

  • HMAC the token cache key. tokenCacheKey hashed a user-chosen password with a bare SHA-256, which CodeQL flagged (alert 479). The key never leaves the process, but a password is low-entropy enough to brute-force out of a plain digest if a key ever reached a heap dump or a debug log. It is now createHmac('sha256', env.INTERNAL_API_SECRET) over the same tuple, so the digest is useless without the server secret. Deliberately not a password-hashing KDF: this runs on every token fetch and partitions a cache rather than verifying a stored credential, so bcrypt/argon2 would add latency for no gain. That reasoning is in TSDoc on the function.
  • Carve exchange rates out of the wand prompt. The shared body wand prompt claimed every payload family is camelCase. sap_concur_upload_exchange_rates is in BODY_OPS and genuinely takes snake_case (currency_sets of { from_crn_code, to_crn_code, start_date, rate }), so the blanket claim produced bodies Concur rejects.
  • Wire the travel-request sendback comment. move_travel_request accepts a documented query comment that Concur applies to the sendback action, but the params branch never forwarded it and the block's only comment field is gated to create_report_comment, so it was unreachable from the UI. Uses a dedicated sendbackComment subblock — sharing the existing id would clash on required-ness and let values bleed between the two operations.

Type of Change

  • Bug fix

Testing

Tested manually. bun run check:audits (29/29), check-block-registry, lint, type-check, and the 127 SAP Concur tests all pass against current staging.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…asing

The cache key hashed a user-chosen password with a bare SHA-256. The key
never leaves the process, but a password is low-entropy enough to
brute-force out of a plain digest if one ever reached a heap dump or a
debug log, which is what CodeQL flags. Keying the digest with a
server-side secret makes it useless without that secret. A
password-hashing KDF would be the wrong tool here: this runs on every
token fetch, and the goal is collision-free partitioning rather than
verification of a stored credential.

The body wand prompt also claimed every payload family is camelCase.
Exchange rate uploads are the exception — they take a snake_case
currency_sets array of from_crn_code, to_crn_code, start_date and rate —
and that operation is in BODY_OPS, so the blanket claim produced bodies
Concur rejects.
… block

move_travel_request accepts a documented query comment that Concur
applies to the sendback action, but the params branch never passed it
and the block's only comment field is gated to create_report_comment, so
the value was unreachable from the UI.

Uses a dedicated sendbackComment subblock rather than widening the
existing comment field: that one is required for create_report_comment
while this is optional, so sharing an id would both clash on
required-ness and let a value bleed between the two operations.
@vercel

vercel Bot commented Aug 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 18, 2026 12:01am

Request Review

@cursor

cursor Bot commented Aug 17, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes derive cache keys from credentials using a server secret and wire a new Concur query parameter; scope is SAP Concur-only but touches auth-adjacent caching behavior.

Overview
Cherry-picked follow-up for SAP Concur: security on token caching, travel sendback comments, and wand body guidance for exchange rates.

Token cache key in shared.ts now uses createHmac('sha256', env.INTERNAL_API_SECRET) over the same credential tuple instead of a plain SHA-256 digest, addressing CodeQL concern that low-entropy password material in the key could be brute-forced from logs or heap dumps. TSDoc explains why HMAC is used instead of a password KDF (cache partitioning on every fetch, not credential verification).

Move travel request (sendback) gains a dedicated advanced Sendback Comment subblock (sendbackComment), shown only when action is sendback. The params mapper forwards it as the API comment query param for that action only—separate from report Comment on create_report_comment.

Request Body wand prompt no longer claims all families are camelCase; it documents exchange rates as snake_case (currency_sets, from_crn_code, etc.) so generated JSON matches sap_concur_upload_exchange_rates.

Reviewed by Cursor Bugbot for commit a21f854. Configure here.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR secures SAP Concur token-cache keys with a server-secret HMAC, corrects exchange-rate prompt casing, and wires sendback comments through the block configuration.

  • Uses INTERNAL_API_SECRET to HMAC the complete JSON-encoded credential tuple.
  • Documents exchange-rate payloads as the snake_case exception.
  • Shows and forwards the travel-request comment only for the sendback action.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; both previously reported issues are fixed in the current code.

Important Files Changed

Filename Overview
apps/sim/app/api/tools/sap_concur/shared.ts Replaces the bare cache-key digest with an HMAC and consolidates the function documentation into one accurate TSDoc block.
apps/sim/blocks/blocks/sap_concur.ts Corrects exchange-rate prompt guidance and safely gates sendback-comment visibility and forwarding by operation and action.

Reviews (2): Last reviewed commit: "fix(sap_concur): gate the sendback comme..." | Re-trigger Greptile

Comment thread apps/sim/blocks/blocks/sap_concur.ts
Comment thread apps/sim/app/api/tools/sap_concur/shared.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c1c3e69. Configure here.

The sendbackComment field was conditioned only on the operation, so it
rendered for submit, approve, cancel and every other workflow action
even though Concur applies the comment to sendback alone. It is now
gated on the action as well, and the params branch only forwards it for
sendback so a value retained from an earlier sendback cannot ride along
once the field is hidden.

Also folds the two consecutive TSDoc blocks left above tokenCacheKey
into one. Only the nearest block binds to the declaration, so the
separator and collision reasoning in the earlier block was detached.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a21f854. Configure here.

@waleedlatif1
waleedlatif1 merged commit aa367a4 into staging Aug 18, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/concur-hmac-and-sendback branch August 18, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant