CVE-2025-30223: Github.com/beego/beego/v2 Cross-Site Scripting Vulnerability

CRITICAL
Advisory Identifier: GHSA-2j42-h78h-q4fg
CVSS 9.3
CWE-79
Published
Advisory Summary

CVE-2025-30223 is a CRITICAL (CVSS 9.3) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Github.com/beego/beego/v2 libraries in the Go ecosystem. The issue involves beego allows reflected/stored xss in beego's renderform() function due to unescaped user input. Remediation is available by upgrading affected packages to version 2.3.6.

CVE-2025-30223 at a Glance

CVE Identifier CVE-2025-30223
GHSA Identifier GHSA-2j42-h78h-q4fg
Severity CRITICAL
CVSS v3.1 Base Score 9.3
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Github.com/beego/beego/v2
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 9.3

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2025-30223

To remediate this vulnerability, upgrade all affected Github.com/beego/beego/v2 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/beego/beego/v2 fixed: 2.3.6
Upgrade github.com/beego/beego/v2 to 2.3.6
github.com/beego/beego fixed: Latest secure release
Upgrade github.com/beego/beego to Latest secure release
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/beego/beego/v2

How to Check if You Are Affected

To determine whether your application is affected by CVE-2025-30223, inspect your project dependencies for Github.com/beego/beego/v2:

inspect dependencies for github.com/beego/beego/v2

Analyze the terminal output to locate any version of Github.com/beego/beego/v2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.3.6), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Github.com/beego/beego/v2, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary A Cross-Site Scripting (XSS) vulnerability exists in Beego's `RenderForm()` function due to improper HTML escaping of user-controlled data. This vulnerability allows attackers to inject malicious JavaScript code that executes in victims' browsers, potentially leading to session hijacking, credential theft, or account takeover. The vulnerability affects any application using Beego's `RenderForm()` function with user-provided data. Since it is a high-level function generating an entire form markup, many developers would assume it automatically escapes attributes (the way most frameworks do). ### Details The vulnerability is located in the `renderFormField()` function in Beego's `templatefunc.go` file (around lines 316-356). This function directly injects user-provided values into HTML without proper escaping: ```go return fmt.Sprintf(`%v<input%v%v name="%v" type="%v" value="%v"%v>`, label, id, class, name, fType, value, requiredString) ``` None of the values (label, id, class, name, value) are properly HTML-escaped before being inserted into the HTML template. This allows attackers to break out of the attribute context or inject HTML tags directly. The vulnerability can be exploited in two main ways: - Attribute Injection: By injecting code into fields like DisplayName, an attacker can break out of the attribute context and execute JavaScript. - Content Injection: By injecting HTML tags into textarea content, an attacker can execute JavaScript. The `RenderForm()` function returns `template.HTML`, which bypasses Go's automatic HTML escaping, making this vulnerability particularly dangerous. ### PoC Retrieve the following (secret) gist: https://gist.github.com/thevilledev/8fd0cab3f098320aa9daab04be59fd2b To run it: ```go go mod init beego-xss-poc go mod tidy go run poc.go ``` Open your browser and navigate to http://localhost:8080/ The application demonstrates the vulnerability through several examples: - `/profile` - Shows a profile with malicious data in the Display Name and Bio fields - `/admin` - Shows multiple user profiles, including one with malicious data - `/submit` - Allows you to create your own profile with malicious data In addition, you may use this Go test in `templatefunc_test.go`. The test passes, validating the vulnerability. ```go func TestRenderFormXSSVulnerability(t *testing.T) { type UserProfile struct { DisplayName string `form:"displayName,text,Name:"` Bio string `form:",textarea"` } // Test case 1: Attribute injection in input field maliciousUser := UserProfile{ DisplayName: `" onmouseover="alert('XSS')" data-malicious="`, Bio: "Normal bio text", } output := RenderForm(&maliciousUser) // The vulnerable output would contain the unescaped JavaScript if !strings.Contains(string(output), `onmouseover="alert('XSS')"`) { t.Errorf("Expected XSS vulnerability in attribute, but got safe output: %v", output) } // Test case 2: Script injection in textarea maliciousUser2 := UserProfile{ DisplayName: "Normal Name", Bio: `</textarea><script>alert('XSS')</script><textarea>`, } output = RenderForm(&maliciousUser2) // The vulnerable output would contain the unescaped script tag if !strings.Contains(string(output), `</textarea><script>alert('XSS')`) { t.Errorf("Expected XSS vulnerability in textarea content, but got safe output: %v", output) } } ``` ### Impact This is a high-severity vulnerability with the following impacts: - Cross-Site Scripting (XSS): Allows execution of arbitrary JavaScript in the context of the victim's browser. - Session Hijacking: Attackers can steal session cookies and impersonate victims. - Credential Theft: Attackers can create fake login forms to steal credentials. - Account Takeover: Attackers can perform actions on behalf of the victim. - Data Exfiltration: Sensitive data visible in the browser can be stolen. This is particularly concerning in admin panels or user management interfaces where one user's data is displayed to another user (typically an administrator). ### Mitigation The vulnerability can be fixed by properly escaping all user-provided values before inserting them into HTML, for example: ```go // Convert value to string and escape it valueStr := "" if value != nil { valueStr = template.HTMLEscapeString(fmt.Sprintf("%v", value)) } // Escape the name and label escapedName := template.HTMLEscapeString(name) escapedLabel := template.HTMLEscapeString(label) escapedType := template.HTMLEscapeString(fType) return fmt.Sprintf(`%v<input%v%v name="%v" type="%v" value="%v"%v>`, escapedLabel, id, class, escapedName, escapedType, valueStr, requiredString) ```

CVE-2025-30223 Affected Github.com/beego/beego/v2 Versions

2 component(s)
Fixed Versions:
2.3.6
Product / Package Ecosystem Affected Versions Fixed Version
github.com/beego/beego/v2
Go
< 2.3.6
2.3.6
github.com/beego/beego
Go
≤ 1.12.14

References

Frequently Asked Questions

What is CVE-2025-30223?
CVE-2025-30223 is a security vulnerability in Github.com/beego/beego/v2 involving Beego allows Reflected/Stored XSS in Beego's RenderForm() Function Due to Unescaped User Input under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Github.com/beego/beego/v2 versions are affected?
Affected versions include releases prior to 2.3.6 across affected packages: github.com/beego/beego/v2, github.com/beego/beego.
What version fixes CVE-2025-30223?
Upgrading to 2.3.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/beego/beego/v2 affected?
Yes, github.com/beego/beego/v2 is affected in releases prior to 2.3.6. Upgrade your dependency to 2.3.6 or later.
Is github.com/beego/beego affected?
Yes, github.com/beego/beego is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What is the CVSS score of CVE-2025-30223?
CVE-2025-30223 has a CVSS v3.1 base score of 9.3 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N.
What CWE is associated with CVE-2025-30223?
CVE-2025-30223 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check Go dependencies for CVE-2025-30223?
Run the dependency tree command: 'inspect dependencies for github.com/beego/beego/v2'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-2j42-h78h-q4fg",
  "modified" : "2025-08-04T15:12:27Z",
  "published" : "2025-03-31T16:55:22Z",
  "aliases" : [ "CVE-2025-30223" ],
  "summary" : "Beego allows Reflected/Stored XSS in Beego's RenderForm() Function Due to Unescaped User Input",
  "details" : "### Summary\n\nA Cross-Site Scripting (XSS) vulnerability exists in Beego's `RenderForm()` function due to improper HTML escaping of user-controlled data. This vulnerability allows attackers to inject malicious JavaScript code that executes in victims' browsers, potentially leading to session hijacking, credential theft, or account takeover. The vulnerability affects any application using Beego's `RenderForm()` function with user-provided data. Since it is a high-level function generating an entire form markup, many developers would assume it automatically escapes attributes (the way most frameworks do).\n\n### Details\n\nThe vulnerability is located in the `renderFormField()` function in Beego's `templatefunc.go` file (around lines 316-356). This function directly injects user-provided values into HTML without proper escaping:\n\n```go\nreturn fmt.Sprintf(`%v<input%v%v name=\"%v\" type=\"%v\" value=\"%v\"%v>`, \n    label, id, class, name, fType, value, requiredString)\n```\n\nNone of the values (label, id, class, name, value) are properly HTML-escaped before being inserted into the HTML template. This allows attackers to break out of the attribute context or inject HTML tags directly.\nThe vulnerability can be exploited in two main ways:\n\n- Attribute Injection: By injecting code into fields like DisplayName, an attacker can break out of the attribute context and execute JavaScript.\n- Content Injection: By injecting HTML tags into textarea content, an attacker can execute JavaScript.\n\nThe `RenderForm()` function returns `template.HTML`, which bypasses Go's automatic HTML escaping, making this vulnerability particularly dangerous.\n\n### PoC\n\nRetrieve the following (secret) gist: https://gist.github.com/thevilledev/8fd0cab3f098320aa9daab04be59fd2b\n\nTo run it:\n\n```go\ngo mod init beego-xss-poc\ngo mod tidy\ngo run poc.go\n```\n\nOpen your browser and navigate to http://localhost:8080/\n\nThe application demonstrates the vulnerability through several examples:\n- `/profile` - Shows a profile with malicious data in the Display Name and Bio fields\n- `/admin` - Shows multiple user profiles, including one with malicious data\n- `/submit` - Allows you to create your own profile with malicious data\n\nIn addition, you may use this Go test in `templatefunc_test.go`. The test passes, validating the vulnerability.\n\n```go\nfunc TestRenderFormXSSVulnerability(t *testing.T) {\n\ttype UserProfile struct {\n\t\tDisplayName string `form:\"displayName,text,Name:\"`\n\t\tBio         string `form:\",textarea\"`\n\t}\n\n\t// Test case 1: Attribute injection in input field\n\tmaliciousUser := UserProfile{\n\t\tDisplayName: `\" onmouseover=\"alert('XSS')\" data-malicious=\"`,\n\t\tBio:         \"Normal bio text\",\n\t}\n\n\toutput := RenderForm(&maliciousUser)\n\n\t// The vulnerable output would contain the unescaped JavaScript\n\tif !strings.Contains(string(output), `onmouseover=\"alert('XSS')\"`) {\n\t\tt.Errorf(\"Expected XSS vulnerability in attribute, but got safe output: %v\", output)\n\t}\n\n\t// Test case 2: Script injection in textarea\n\tmaliciousUser2 := UserProfile{\n\t\tDisplayName: \"Normal Name\",\n\t\tBio:         `</textarea><script>alert('XSS')</script><textarea>`,\n\t}\n\n\toutput = RenderForm(&maliciousUser2)\n\n\t// The vulnerable output would contain the unescaped script tag\n\tif !strings.Contains(string(output), `</textarea><script>alert('XSS')`) {\n\t\tt.Errorf(\"Expected XSS vulnerability in textarea content, but got safe output: %v\", output)\n\t}\n}\n```\n\n### Impact\n\nThis is a high-severity vulnerability with the following impacts:\n\n- Cross-Site Scripting (XSS): Allows execution of arbitrary JavaScript in the context of the victim's browser.\n- Session Hijacking: Attackers can steal session cookies and impersonate victims.\n- Credential Theft: Attackers can create fake login forms to steal credentials.\n- Account Takeover: Attackers can perform actions on behalf of the victim.\n- Data Exfiltration: Sensitive data visible in the browser can be stolen.\n\nThis is particularly concerning in admin panels or user management interfaces where one user's data is displayed to another user (typically an administrator).\n\n### Mitigation\n\nThe vulnerability can be fixed by properly escaping all user-provided values before inserting them into HTML, for example:\n\n```go\n// Convert value to string and escape it\nvalueStr := \"\"\nif value != nil {\n    valueStr = template.HTMLEscapeString(fmt.Sprintf(\"%v\", value))\n}\n\n// Escape the name and label\nescapedName := template.HTMLEscapeString(name)\nescapedLabel := template.HTMLEscapeString(label)\nescapedType := template.HTMLEscapeString(fType)\n\nreturn fmt.Sprintf(`%v<input%v%v name=\"%v\" type=\"%v\" value=\"%v\"%v>`, \n    escapedLabel, id, class, escapedName, escapedType, valueStr, requiredString)\n```",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/beego/beego/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.3.6"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/beego/beego"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "1.12.14"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/beego/beego/security/advisories/GHSA-2j42-h78h-q4fg"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-30223"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/beego/beego/commit/939bb18c66406466715ddadd25dd9ffa6f169e25"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/beego/beego"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2025-3585"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-03-31T16:55:22Z",
    "nvd_published_at" : "2025-03-31T17:15:42Z"
  }
}