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

remove sql inject pattern (--) #85

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class XssSqlUtil {
private static final String STR_JS = "javascript:";
private static final String STR_VB = "vbscript:";
private static final String STR_ON = "onload(.*?)=";
private static final String SQL = "('.+--)|(--)|(%7C)";
private static final String SQL = "('.+--)|(%7C)";

private static final Pattern SCRIPT1_PATTERN = Pattern.compile(STR_SCRIPT1, Pattern.CASE_INSENSITIVE);
private static final Pattern SCRIPT2_PATTERN = Pattern.compile(STR_SCRIPT2, Pattern.CASE_INSENSITIVE);
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/java/com/usthe/sureness/security/XssSqlUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.usthe.sureness.security;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* @author tomsun28
* @date 2021/4/2 21:38
*/
class XssSqlUtilTest {

@Test
void stripXss() {
String xssTmp = "cc<script>is a book</script>BB";
assertEquals("ccBB", XssSqlUtil.stripXss(xssTmp));
}

@Test
void stripSqlInjection() {
String jwtTmp = "good is girl--boy";
assertEquals(jwtTmp, XssSqlUtil.stripSqlInjection(jwtTmp));
String sqlInject = "select * from tableDb where d = 'sds' -- update";
assertNotEquals(sqlInject, XssSqlUtil.stripSqlInjection(sqlInject));
assertEquals("select * from tableDb where d = update", XssSqlUtil.stripSqlInjection(sqlInject));
}
}