Fix: Stored XSS via article.link_to in _ArticleController - #195
Open
milo2012 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Fix stored XSS via
article.link_toin_ArticleController(/admin/article/doWriteSave)Summary
Fixes a stored cross-site scripting (XSS) vulnerability in the article
writing endpoint
/admin/article/doWriteSave. Thearticle.link_tofield (external link) was persisted without URL validation and later
rendered unescaped in HTML attribute/href contexts, allowing a malicious
payload to execute JavaScript in an administrator's or visitor's browser.
Vulnerable file
module-article/module-article-web/src/main/java/io/jpress/module/article/controller/admin/_ArticleController.javaRoot cause
doWriteSave()binds the raw request intoArticleviagetModel(...).JFinal's model injection does not escape parameter values.
Article.save()/update()passlink_tothroughCommonsUtils.escapeModel+JsoupUtils.clean, but Jsoup cleaning onlystrips HTML tags. It does NOT stop attribute-breakout payloads because
a double quote is a valid quote to the HTML parser inside an attribute,
e.g.:
" onmouseover="alert(document.cookie)" data-x="The stored value is later output with NO HTML escaping:
value="#unescape(article.link_to ??)"(article_write.html)<a href="#(item.url ??)">查看</a>(article_list.html)<a href="#(article.url ??)">(==Article.getUrl()==getLinkTo())Result: hovering a crafted link fires JavaScript.
Fix
Added input validation
validateLinkTo(Article)in_ArticleController,called at the top of
doWriteSave()(beforevalidateSlug). When thesubmitted
link_tovalue is unsafe, the request is rejected withRet.fail("message", ...)and nothing is persisted.The validation:
\n/\t-based protocol- orcharacter-bypass attempts),
<,>,",',`(blocks HTML tag andattribute injection),
javascript:,vbscript:,data:,file:(allows http/https-jsoup-style links, relative paths and anchors).
Files changed
module-article/module-article-web/src/main/java/io/jpress/module/article/controller/admin/_ArticleController.java