GitHub Security Advisory: GHSA-x7wh-g25g-53vg
Package: ci4-cms-erp/ci4ms (COMPOSER)
Severity: CRITICAL (CVSS 9.1)
CWE: CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Vulnerable versions: <= 0.28.6.0
Patched in: 0.31.0.0

Summary: CI4MS: Blogs Posts Full Account Takeover for All-Roles & Privilege-Escalation via Stored DOM XSS

Details:
## Summary
### **Vulnerability: Stored DOM XSS via Blog Post Content (Persistent Payload Injection)**
- Stored Cross-Site Scripting via Unsanitized Blog Post Content in Blog Management

### Description
The application fails to properly sanitize user-controlled input when creating or editing blog posts. An attacker can inject a malicious JavaScript payload into blog post content, which is then stored server-side.

This stored payload is later rendered unsafely in multiple application views without proper output encoding, leading to stored cross-site scripting (XSS).

### Affected Functionality
- Blog post creation functionality
- Blog post editing functionality
- Blog post storage and retrieval logic

### Attack Scenario
- An attacker creates or edits a blog post to include a malicious XSS payload.
- The application stores this content without sanitization or encoding.
- The payload persists and executes whenever the blog post is rendered in affected views.

### Impact
- Persistent Stored XSS
- Execution of arbitrary JavaScript in victims’ browsers
- Privilege escalation when viewed by administrators or privileged users
- Full administrator account takeover
- Full account takeover across all roles
- Full compromise of the entire application

Endpoints:
- `/backend/blogs/create`
- `/backend/blogs/`
- `/blog/{id}`

## Steps To Reproduce (POC)
1. Go to the Blog Post Create or Edit page
2. Insert an XSS payload into the blog post content such as:
`<img src=x onerror=alert(document.domain)>`
3. Save or publish the blog post
4. View the post via the administrative panel or public blog page
5. Notice the XSS payload executing automatically

## Remediation

- **Avoid unsafe DOM manipulation methods:** Do not use `.html()`, `innerHTML`, or similar sink functions in client-side JavaScript or server-side templating (e.g., PHP). Even when user input flowing into these sinks is not immediately apparent, they can introduce Cross-Site Scripting (XSS) vulnerabilities that an attacker may exploit.

- **Apply output encoding:** Implement HTML entity encoding on all user-controlled data before rendering it in the browser. This helps neutralize potentially malicious input.

- **Implement input sanitization:** Ensure that all user-supplied input is properly sanitized before processing or output. Currently, no sanitization mechanisms are in place, which should be addressed as a priority.

- **Enforce security headers and cookie attributes:**
  - **Content Security Policy (CSP):** Define and enforce a strict CSP to limit the execution of unauthorized scripts.
  - **HttpOnly flag:** Set the `HttpOnly` attribute on session cookies to prevent client-side script access.
  - **SameSite attribute:** Configure the `SameSite` cookie attribute to mitigate Cross-Site Request Forgery (CSRF) risks.
  - **Secure flag:** Ensure all cookies are transmitted only over HTTPS by enabling the `Secure` attribute.

  These measures collectively reduce the impact of XSS and help prevent escal