## Jeesns Article Store XSS
### Introduction to Vulnerability
JEESNS is a social management system based on JAVA enterprise-level platform. Based on the advantages of enterprise-level JAVA, such as high efficiency, security and stability, it creates a pioneering domestic Java version of open source SNS. JEESNS can be used to build portals, forums, communities, Weibo, Q&A, knowledge payment platform, etc. In Jeesns <= 1.4.2, the article's input filtering is incomplete, resulting in a stored XSS vulnerability.
### Vulnerability Impact
* Jeesns <= 1.4.2
### Vulnerability Analysis
The data submitted by the user foreground will pass XSSFilter, and the doFilter will call XssWrapper.
```java
Package com.lxinet.jeesns.core.utils;
Import java.util.regex.Matcher;
Import java.util.regex.Pattern;
Import javax.servlet.http.HttpServletRequest;
Import javax.servlet.http.HttpServletRequestWrapper;
Import org.springframework.web.util.HtmlUtils;
Public class XssWrapper extends HttpServletRequestWrapper {
Private static final String REGEX_SCRIPT = "<script[\\s\\S]*?<\\/script>";
Private static final String REGEX_STYLE = "<style[^>]*?>[\\s\\S]*?<\\/style>";
......
Public String getParameter(String parameter) {
String value = super.getParameter(parameter);
Return value == null ? null : this.cleanXSS(value);
}
Public String getHeader(String name) {
String value = super.getHeader(name);
Return value == null ? null : this.cleanXSS(value);
}
Private String cleanXSS(String value) {
Value = dealScript(value);
Value = dealStyle(value);
String[] eventKeywords = new String[]{"onmouseover", "onmouseout", "onmousedown", "onmouseup", "onmousemove", "onclick", "ondblclick", "onkeypress", "onkeydown", "onkeyup", "ondragstart", "onerrorupdate", "onhelp", "onreadystatechange", "onrowenter", "onrowexit", "onselectstart", "onload", "onunload", "onbeforeunload", "onblur", "onerror", "onfocus ", "onresize", "onscroll", "oncontextmenu", "alert"};
For(int i = 0; i < eventKeywords.length; ++i) {
Value = value.replaceAll("(?i)" + eventKeywords[i], "_" + eventKeywords[i]);
}
Return value;
}
Private static String dealScript(String val) {
Pattern p = Pattern.compile("<script[\\s\\S]*?<\\/script>");
Return htmlEscape(p, val);
}
Private static String dealStyle(String val) {
Pattern p = Pattern.compile("<style[^>]*?>[\\s\\S]*?<\\/style>");
Return htmlEscape(p, val);
}
Private static String htmlEscape(Pattern p, String val) {
String s;
String newVal;
For(Matcher m = p.matcher(val); m.find(); val = val.replace(s, newVal)) {
s = m.group();
newVal = HtmlUtils.htmlEscape(s);
}
Return val;
}
}
```
As you can see, the `<script>` and `<style>` tags are filtered, and some HTML events are escaped and filtered. However, when matching tags, there is no case processing, which can be bypassed by capitalization.
See the `save()` of the function `jeesns-service\src\main\java\com\lxinet\jeesns\service\cms\impl\ArticleServiceImpl.java` where the article is saved.
```java
@Override
@Transactional
Public boolean save(Member member, Article article) {
Map<String,String> config = configService.getConfigToMap();
If(member.getIsAdmin() == 0 && "0".equals(config.get(ConfigUtil.CMS_POST))){
Throw new OpeErrorException("Submission function is off");
}
If(article.getCateId() == null || article.getCateId() == 0){
Throw new ParamException("The column cannot be empty");
}
article.setMemberId(member.getId());
If(member.getIsAdmin() == 0 && "0".equals(config.get(ConfigUtil.CMS_POST_REVIEW))){
article.setStatus(0);
}else {
article.setStatus(1);
}
If (article.getViewCount() == null) {
article.setViewCount(0);
}
If (article.getViewRank() == null) {
article.setViewRank(0);
}
If (StringUtils.isEmpty(article.getDescription())) {
String contentStr = HtmlUtil.delHTMLTag(article.getContent());
If (contentStr.length() > 200) {
article.setDescription(contentStr.substring(0, 200));
} else {
article.setDescription(contentStr);
}
}
If (StringUtils.isEmpty(article.getThumbnail())) {
Document doc = Jsoup.parseBodyFragment(article.getContent());
Elements elements = doc.select("img[src]");
If (elements.size() > 0) {
String imgsrc = elements.get(0).attr("src");
article.setThumbnail(imgsrc);
}else{
article.setThumbnail(null);
}
}
Boolean result = super.save(article);
```
The data of the user condition is not further filtered, and is directly saved to the database, and then the front end directly renders, resulting in a storage type XSS.
### Vulnerability reproduction
1. Register a user.
2. Post the article and fill in the XSS payload `<Script>prompt(/xss/)</Script>`.
![](https://images.seebug.org/1557817372788-w331s)
3. Posting an article requires review, and XSS is triggered when the background administrator views the article.
![](https://images.seebug.org/1557817379659-w331s)
暂无评论