Repository navigation
[AI] Add SSRF protection to SimpleFIN bank sync integration - #8012
Conversation
The SimpleFIN integration made server-side HTTP requests to user-controlled URLs (the base64-encoded claim token and the resulting access-key base URL) without any validation, unlike the CORS proxy which blocks private IPs via ipaddr.js. Add a shared assertUrlAllowed() helper that rejects non-http(s) URLs and blocks requests to private, loopback, link-local, unique-local, reserved, broadcast and unspecified addresses. Hostnames are resolved via DNS so names pointing at internal addresses are blocked too, not just literal IPs. Apply it before both outbound requests in getAccessKey() and getAccounts().
The CORS proxy had its own inline ipaddr.js private-IP check that duplicated the logic in the SimpleFIN SSRF helper. Export isBlockedIp() from util/ssrf and reuse it in app-cors-proxy, removing the duplicate. This also widens the CORS proxy's coverage to the reserved and broadcast ranges and normalizes IPv4-mapped IPv6 addresses, matching the SimpleFIN helper. The cors-proxy tests now exercise the real ipaddr.js against real private IPs instead of mocking it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
✅ Deploy Preview for actualbudget-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a centralized SSRF utility ( ChangesSSRF Protection Implementation
🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Requests to private, loopback, link-local, and other internal addresses are now blocked.
✅ Deploy Preview for actualbudget-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
upcoming-release-notes/8012.md (1)
6-6: ⚡ Quick winUse a more user-facing phrasing in the release note body.
This is concise already, but replacing “SSRF” with plain language would better match release-note style (non-technical for Bugfix entries).
Suggested wording
-Add SSRF protection to the SimpleFIN bank sync integration. +Improved security for SimpleFIN bank sync to block unsafe internal network requests.Based on learnings: “For files in upcoming-release-notes/*.md, keep release notes concise: ideally one sentence and non-technical content unless the category is Maintenance.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@upcoming-release-notes/8012.md` at line 6, Update the release note line that currently reads "Add SSRF protection to the SimpleFIN bank sync integration." to a concise, non-technical one-sentence phrasing such as "Added protection against malicious external requests in the SimpleFIN bank sync integration." — replace the existing sentence in upcoming-release-notes/8012.md (the line containing "Add SSRF protection to the SimpleFIN bank sync integration.") with the new user-facing wording and keep it to a single sentence.packages/sync-server/src/util/ssrf.ts (1)
36-85: 💤 Low valueConsider documenting the TOCTOU/DNS rebinding limitation.
The implementation resolves DNS at check time, but the downstream
fetch/https.requestwill resolve DNS again independently. A sophisticated attacker controlling DNS could return a safe IP on the first lookup (passing validation) and a blocked IP on the second lookup (reaching the internal service).This is a known limitation of pre-flight DNS validation. The current implementation still provides strong protection against most SSRF vectors. A more robust mitigation would require returning resolved IPs and forcing the HTTP client to connect to those specific addresses (e.g., via custom Agent or socket connect override), but that's a more invasive change.
For now, consider adding a brief comment noting this limitation for future maintainers.
📝 Suggested documentation
/** * Validate that a URL is safe to make a server-side request to, guarding * against SSRF. Only http(s) URLs are permitted, and the hostname is resolved * via DNS so that hostnames pointing at private/local/link-local addresses are * rejected as well as literal IPs. Throws if the URL is not allowed. + * + * Note: This is a pre-flight check; the actual HTTP client will resolve DNS + * independently, leaving a small TOCTOU window for DNS rebinding attacks. + * For higher-assurance scenarios, consider pinning the resolved address in the + * HTTP agent. */ export async function assertUrlAllowed(targetUrl: string): Promise<void> {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sync-server/src/util/ssrf.ts` around lines 36 - 85, The assertUrlAllowed function performs DNS resolution at check time but does not prevent a TOCTOU/DNS-rebinding attack because downstream HTTP clients will re-resolve the hostname; add a concise comment above assertUrlAllowed explaining this limitation (DNS race/rebinding), noting that a stronger mitigation would require returning resolved IPs and forcing connections to those addresses (e.g., custom Agent or socket override), and reference that any future change should ensure the HTTP client uses the validated IPs to avoid re-resolution.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/sync-server/src/util/ssrf.ts`:
- Around line 36-85: The assertUrlAllowed function performs DNS resolution at
check time but does not prevent a TOCTOU/DNS-rebinding attack because downstream
HTTP clients will re-resolve the hostname; add a concise comment above
assertUrlAllowed explaining this limitation (DNS race/rebinding), noting that a
stronger mitigation would require returning resolved IPs and forcing connections
to those addresses (e.g., custom Agent or socket override), and reference that
any future change should ensure the HTTP client uses the validated IPs to avoid
re-resolution.
In `@upcoming-release-notes/8012.md`:
- Line 6: Update the release note line that currently reads "Add SSRF protection
to the SimpleFIN bank sync integration." to a concise, non-technical
one-sentence phrasing such as "Added protection against malicious external
requests in the SimpleFIN bank sync integration." — replace the existing
sentence in upcoming-release-notes/8012.md (the line containing "Add SSRF
protection to the SimpleFIN bank sync integration.") with the new user-facing
wording and keep it to a single sentence.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2922d55c-4633-4207-9244-a20732d17593
📒 Files selected for processing (6)
packages/sync-server/src/app-cors-proxy.jspackages/sync-server/src/app-cors-proxy.test.jspackages/sync-server/src/app-simplefin/app-simplefin.jspackages/sync-server/src/util/ssrf.test.tspackages/sync-server/src/util/ssrf.tsupcoming-release-notes/8012.md
💤 Files with no reviewable changes (1)
- packages/sync-server/src/app-cors-proxy.test.js
| // IP ranges (as classified by ipaddr.js) that must never be reachable from | ||
| // server-side requests to user-controlled URLs. linkLocal covers the cloud | ||
| // metadata endpoint (169.254.169.254). | ||
| const BLOCKED_IP_RANGES = [ |
There was a problem hiding this comment.
Could we make this configurable? Speaking at least personally, I run my services on a local IP (over Tailscale), and this change would prevent me from running my own SimpleFIN server. Ideally I could do something like "add x IP to allowed IPs" and it would override the blocklist.
There was a problem hiding this comment.
Thanks for pointing this out. I have made some updates to allow local IP usage. Not a big fan of adding a special env var here as it creates friction for self-hosters. Not something we'd want to intentionally add.
WDYT now?
Full disclosure: I don't use simplefin so didn't test this manually. I think it should be fine, but I'm not 100% confident.
There was a problem hiding this comment.
Hmm, this should definitely address my concern! Personally I'd slightly prefer an environment variable because I know the exact IP that corresponds to my reverse proxy (vs something else), and I do feel like it should be disabled by default so we have "good" defaults eg for pikapods. That would be a breaking change though, so understand where you're coming from. (FWIW, several other open-source projects I use recently made a change to a similar effect.)
Will give this a test when I'm home tonight!
|
I think this should be fine, but would appreciate someone on SimpleFin testing it out (I'm on Gocardless). |
The SSRF protection blocked all private/loopback addresses, which broke
self-hosters running their own SimpleFIN bridge on a LAN or VPN IP with
no way to opt back in.
Split the blocked ranges into two tiers: link-local (cloud metadata),
reserved, broadcast and unspecified stay blocked unconditionally, while
private/loopback/unique-local are blocked by default but can be permitted
per-caller via { allowPrivateNetwork: true }. SimpleFIN opts in, so
self-hosting works out of the box with no env var, while the worst-case
cloud-metadata credential-theft vector remains closed. The CORS proxy
keeps the strict default.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rf-protection-Du3JD
✅ Deploy Preview for actualbudget-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/sync-server/src/app-simplefin/app-simplefin.js (1)
393-399:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix SSRF bypass via automatic redirect following in
getAccounts
packages/sync-server/src/app-simplefin/app-simplefin.jscallsassertUrlAllowed(url.toString(), { allowPrivateNetwork: true })once, but then doesfetch(url.toString(), { redirect: 'follow' }). A hostile bridge can return a 30x with aLocationto a blocked destination;fetchwill follow it and bypass the SSRF enforcement.
Disable redirect following or manually follow redirects and runassertUrlAllowed()on everyLocationhop.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sync-server/src/app-simplefin/app-simplefin.js` around lines 393 - 399, The fetch call in getAccounts currently uses redirect: 'follow' which allows 30x responses to redirect to potentially disallowed locations after the initial assertUrlAllowed(url.toString(), { allowPrivateNetwork: true }) check; change the fetch logic to either (a) set redirect: 'manual' and, if a 3xx is returned, extract the Location header and call assertUrlAllowed(newLocation, { allowPrivateNetwork: true }) before following, repeating for each hop, or (b) implement manual redirect-following loop that performs assertUrlAllowed() on each Location hop before issuing the next fetch; update the code paths around the existing assertUrlAllowed and the fetch(...) call accordingly so no automatic redirect can bypass the check.packages/sync-server/src/util/ssrf.ts (1)
72-118:⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy liftassertUrlAllowed preflights DNS but doesn’t pin the dialed address (TOCTOU/rebinding SSRF risk)
assertUrlAllowed()only returnsPromise<void>and discards the resolved DNS answers; it validates using a singledns.lookup(hostname, { all: true })and never binds the outbound connection to those IPs.Current call sites validate and then still dial using the original hostname:
packages/sync-server/src/app-simplefin/app-simplefin.js(~321):await assertUrlAllowed(token, ...)→https.request(new URL(token), ...)packages/sync-server/src/app-simplefin/app-simplefin.js(~393):await assertUrlAllowed(url.toString(), ...)→fetch(url.toString(), ...)
(no agent/dispatcher pinning to the validated IPs in this file)The
ssrf.test.ts“rebind.example.com” coverage blocks when one lookup result set contains a private IP, but it doesn’t eliminate time-separated DNS rebinding between validation and the socket being opened.Fix by changing
assertUrlAllowed(or adding a new helper) to return the allowed resolved address(es) and have the caller perform the request through those resolved IPs (e.g., wrap the outbound request to use the vetted IP while preservingHost/SNI), rather than relying on the original hostname after preflight.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sync-server/src/util/ssrf.ts` around lines 72 - 118, assertUrlAllowed currently only validates DNS answers and returns void, leaving a TOCTOU/rebinding SSRF risk; change it to return the vetted resolved addresses (e.g., array of IP strings or address objects) instead of discarding them. Update assertUrlAllowed (or add assertUrlAllowedAndResolve) to perform dnsLookup(hostname, { all: true }), filter out blocked IPs using isBlockedIp, throw on any blocked/empty result, and return the remaining resolved addresses to the caller. Then modify callers (e.g., the app-simplefin call sites that call assertUrlAllowed before https.request or fetch) to use the returned IP(s) when opening sockets: pin the socket/agent to a vetted IP (or create a custom Agent/lookup) and preserve the original Host header and SNI by setting the request Host header to url.host and using servername in TLS options; ensure any consumer of dnsLookup/addresses uses the returned addresses rather than re-resolving the hostname.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/sync-server/src/app-simplefin/app-simplefin.js`:
- Around line 393-399: The fetch call in getAccounts currently uses redirect:
'follow' which allows 30x responses to redirect to potentially disallowed
locations after the initial assertUrlAllowed(url.toString(), {
allowPrivateNetwork: true }) check; change the fetch logic to either (a) set
redirect: 'manual' and, if a 3xx is returned, extract the Location header and
call assertUrlAllowed(newLocation, { allowPrivateNetwork: true }) before
following, repeating for each hop, or (b) implement manual redirect-following
loop that performs assertUrlAllowed() on each Location hop before issuing the
next fetch; update the code paths around the existing assertUrlAllowed and the
fetch(...) call accordingly so no automatic redirect can bypass the check.
In `@packages/sync-server/src/util/ssrf.ts`:
- Around line 72-118: assertUrlAllowed currently only validates DNS answers and
returns void, leaving a TOCTOU/rebinding SSRF risk; change it to return the
vetted resolved addresses (e.g., array of IP strings or address objects) instead
of discarding them. Update assertUrlAllowed (or add assertUrlAllowedAndResolve)
to perform dnsLookup(hostname, { all: true }), filter out blocked IPs using
isBlockedIp, throw on any blocked/empty result, and return the remaining
resolved addresses to the caller. Then modify callers (e.g., the app-simplefin
call sites that call assertUrlAllowed before https.request or fetch) to use the
returned IP(s) when opening sockets: pin the socket/agent to a vetted IP (or
create a custom Agent/lookup) and preserve the original Host header and SNI by
setting the request Host header to url.host and using servername in TLS options;
ensure any consumer of dnsLookup/addresses uses the returned addresses rather
than re-resolving the hostname.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8c4c61db-3ce9-430c-9cb0-e808c4ec1649
📒 Files selected for processing (3)
packages/sync-server/src/app-simplefin/app-simplefin.jspackages/sync-server/src/util/ssrf.test.tspackages/sync-server/src/util/ssrf.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/sync-server/src/util/ssrf.test.ts
getAccounts used fetch with redirect: 'follow', so a 3xx response from the validated SimpleFIN URL could redirect to a blocked internal address after only the initial URL had been checked. Follow redirects manually instead, calling assertUrlAllowed on every hop before fetching, capping at 5 redirects, and dropping Authorization on cross-origin hops so the bridge credentials cannot leak to a redirect target. getAccessKey uses https.request, which does not auto-follow redirects, so it is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
tested and works fine using my simplefin token |
…dget#8012) * [AI] Add SSRF protection to SimpleFIN bank sync integration The SimpleFIN integration made server-side HTTP requests to user-controlled URLs (the base64-encoded claim token and the resulting access-key base URL) without any validation, unlike the CORS proxy which blocks private IPs via ipaddr.js. Add a shared assertUrlAllowed() helper that rejects non-http(s) URLs and blocks requests to private, loopback, link-local, unique-local, reserved, broadcast and unspecified addresses. Hostnames are resolved via DNS so names pointing at internal addresses are blocked too, not just literal IPs. Apply it before both outbound requests in getAccessKey() and getAccounts(). * [AI] Unify CORS proxy private-IP check with shared SSRF helper The CORS proxy had its own inline ipaddr.js private-IP check that duplicated the logic in the SimpleFIN SSRF helper. Export isBlockedIp() from util/ssrf and reuse it in app-cors-proxy, removing the duplicate. This also widens the CORS proxy's coverage to the reserved and broadcast ranges and normalizes IPv4-mapped IPv6 addresses, matching the SimpleFIN helper. The cors-proxy tests now exercise the real ipaddr.js against real private IPs instead of mocking it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * [AI] Rename SimpleFIN SSRF release note to match PR number Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Implement SSRF protection for SimpleFIN bank sync Requests to private, loopback, link-local, and other internal addresses are now blocked. * [AI] Allow self-hosted private SimpleFIN servers by default The SSRF protection blocked all private/loopback addresses, which broke self-hosters running their own SimpleFIN bridge on a LAN or VPN IP with no way to opt back in. Split the blocked ranges into two tiers: link-local (cloud metadata), reserved, broadcast and unspecified stay blocked unconditionally, while private/loopback/unique-local are blocked by default but can be permitted per-caller via { allowPrivateNetwork: true }. SimpleFIN opts in, so self-hosting works out of the box with no env var, while the worst-case cloud-metadata credential-theft vector remains closed. The CORS proxy keeps the strict default. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * [AI] Re-validate SSRF rules on each SimpleFIN redirect hop getAccounts used fetch with redirect: 'follow', so a 3xx response from the validated SimpleFIN URL could redirect to a blocked internal address after only the initial URL had been checked. Follow redirects manually instead, calling assertUrlAllowed on every hop before fetching, capping at 5 redirects, and dropping Authorization on cross-origin hops so the bridge credentials cannot leak to a redirect target. getAccessKey uses https.request, which does not auto-follow redirects, so it is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…dget#8012) * [AI] Add SSRF protection to SimpleFIN bank sync integration The SimpleFIN integration made server-side HTTP requests to user-controlled URLs (the base64-encoded claim token and the resulting access-key base URL) without any validation, unlike the CORS proxy which blocks private IPs via ipaddr.js. Add a shared assertUrlAllowed() helper that rejects non-http(s) URLs and blocks requests to private, loopback, link-local, unique-local, reserved, broadcast and unspecified addresses. Hostnames are resolved via DNS so names pointing at internal addresses are blocked too, not just literal IPs. Apply it before both outbound requests in getAccessKey() and getAccounts(). * [AI] Unify CORS proxy private-IP check with shared SSRF helper The CORS proxy had its own inline ipaddr.js private-IP check that duplicated the logic in the SimpleFIN SSRF helper. Export isBlockedIp() from util/ssrf and reuse it in app-cors-proxy, removing the duplicate. This also widens the CORS proxy's coverage to the reserved and broadcast ranges and normalizes IPv4-mapped IPv6 addresses, matching the SimpleFIN helper. The cors-proxy tests now exercise the real ipaddr.js against real private IPs instead of mocking it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * [AI] Rename SimpleFIN SSRF release note to match PR number Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Implement SSRF protection for SimpleFIN bank sync Requests to private, loopback, link-local, and other internal addresses are now blocked. * [AI] Allow self-hosted private SimpleFIN servers by default The SSRF protection blocked all private/loopback addresses, which broke self-hosters running their own SimpleFIN bridge on a LAN or VPN IP with no way to opt back in. Split the blocked ranges into two tiers: link-local (cloud metadata), reserved, broadcast and unspecified stay blocked unconditionally, while private/loopback/unique-local are blocked by default but can be permitted per-caller via { allowPrivateNetwork: true }. SimpleFIN opts in, so self-hosting works out of the box with no env var, while the worst-case cloud-metadata credential-theft vector remains closed. The CORS proxy keeps the strict default. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * [AI] Re-validate SSRF rules on each SimpleFIN redirect hop getAccounts used fetch with redirect: 'follow', so a 3xx response from the validated SimpleFIN URL could redirect to a blocked internal address after only the initial URL had been checked. Follow redirects manually instead, calling assertUrlAllowed on every hop before fetching, capping at 5 redirects, and dropping Authorization on cross-origin hops so the bridge credentials cannot leak to a redirect target. getAccessKey uses https.request, which does not auto-follow redirects, so it is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Description
Patch a security problem w/ SimpleFIN
Related issue(s)
https://github.com/actualbudget/actual/security/advisories/GHSA-q5j6-rc55-rvqx
Testing
N/A
Checklist