Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') in FrontendHandler.go #5

Closed
gtqbhksl opened this issue Sep 3, 2024 · 1 comment

Comments

@gtqbhksl
Copy link

gtqbhksl commented Sep 3, 2024

Cause of vulnerability: A potential Cross-site scripting (XSS) vulnerability exists on line 19 of the FrontendHandler.go file in the code. The vulnerability is caused by user-supplied values being inserted directly into the generated HTML page without proper processing or escaping. Specifically, the 'PageRenderHtmlByAlias' function takes an alias parameter and inserts it directly into the returned HTML string. If an attacker is able to control this alias parameter and inject malicious scripts, these scripts will be executed in the user's browser, resulting in a cross-site scripting attack. This situation is very dangerous because it allows an attacker to execute arbitrary code or steal user information.

FrontendHandler.go line 33-52

func (cms *Cms) FrontendHandlerRenderAsString(w http.ResponseWriter, r *http.Request) string {
	uri := r.RequestURI

	if strings.HasSuffix(uri, ".ico") {
		return ""
	}

	languageAny := r.Context().Value(LanguageKey{})
	language := utils.ToString(languageAny)

	if cms.translationsEnabled {
		isValidLanguage := lo.Contains(lo.Keys(cms.translationLanguages), language)

		if !isValidLanguage {
			language = cms.translationLanguageDefault
		}
	}

	return cms.PageRenderHtmlByAlias(r, r.URL.Path, language)
}

PageBuildHtml.go line 10-22

// PageRenderHtmlByAlias builds the HTML of a page based on its alias
func (cms *Cms) PageRenderHtmlByAlias(r *http.Request, alias string, language string) string {
	page, err := cms.PageFindByAlias(alias)

	if err != nil {
		cms.LogStore.ErrorWithContext("At pageBuldHTMLByAlias", err.Error())
		return "Page with alias '" + alias + "' not found"
	}

	if page == nil {
		return "Page with alias '" + alias + "' not found"
	}

	pageAttrs, err := page.GetAttributes()

	if err != nil {
		return "Page '" + alias + "' io exception"
	}
@lesichkovm
Copy link
Collaborator

Thank you @gtqbhksl . Nice catch

This has now been fixed.

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

No branches or pull requests

2 participants