-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c96c20f
commit 224b5d1
Showing
15 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
server/.gradle/7.6.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
93 changes: 93 additions & 0 deletions
93
server/Recruit-Api/src/main/java/com/econovation/recruit/utils/aop/XssValidationAspect.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.econovation.recruit.utils.aop; | ||
|
||
import com.econovation.recruitcommon.exception.XssScriptAttackException; | ||
import com.econovation.recruitdomain.domains.applicant.dto.BlockRequestDto; | ||
import com.econovation.recruitdomain.domains.applicant.event.ApplicantRegisterEvent; | ||
import com.econovation.recruitinfrastructure.slack.SlackErrorNotificationProvider; | ||
import com.econovation.recruitinfrastructure.slack.SlackMessageProvider; | ||
import com.econovation.recruitinfrastructure.slack.config.SlackProperties; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.*; | ||
import org.springframework.stereotype.Component; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.safety.Whitelist; | ||
|
||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class XssValidationAspect { | ||
private final SlackMessageProvider slackMessageProvider; | ||
private final SlackProperties slackProperties; | ||
|
||
@Around("@annotation(com.econovation.recruitcommon.annotation.XssProtected)") | ||
public Object validateXssInput(ProceedingJoinPoint joinPoint) throws Throwable { | ||
Object[] args = joinPoint.getArgs(); | ||
for (Object arg : args) { | ||
if (arg instanceof List) { | ||
validateDtoList((List<?>) arg); | ||
} | ||
} | ||
return joinPoint.proceed(); | ||
} | ||
|
||
private Boolean validateDtoList(List<?> dtoList) { | ||
for (Object dto : dtoList) { | ||
if (dto instanceof BlockRequestDto) { | ||
Boolean attackSignal = validateBlockRequestDto((BlockRequestDto) dto); | ||
if (attackSignal) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private Boolean validateBlockRequestDto(BlockRequestDto dto) { | ||
String sanitizedAnswer = Jsoup.clean(dto.getAnswer(), Whitelist.relaxed()); | ||
if (!dto.getAnswer().equals(sanitizedAnswer)) { | ||
slackMessageProvider.sendMessage( | ||
slackProperties.getUrl(), | ||
generateApplicantRegisterMessage(dto)); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private String generateApplicantRegisterMessage(BlockRequestDto dto) { | ||
String inputAnswer = dto.getAnswer(); | ||
String sanitizedAnswer = Jsoup.clean(inputAnswer, Whitelist.relaxed()); | ||
|
||
if (!inputAnswer.equals(sanitizedAnswer)) { | ||
// XSS 공격이 의심되는 부분을 추출합니다. | ||
String detectedXss = extractDetectedXss(inputAnswer, sanitizedAnswer); | ||
|
||
// 경고 메시지 생성 | ||
return String.format( | ||
":interrobang::interrobang::interrobang: XSS 공격이 감지되었습니다.:interrobang::interrobang::interrobang:\n\n" | ||
+ ":party_parrot2: 입력값 : %s\n\n" | ||
+ ":party_parrot2: 변환된 공격 추출 값 : %s", | ||
inputAnswer, detectedXss); | ||
} | ||
|
||
// 공격이 감지되지 않은 경우 | ||
return "No XSS attacks detected."; | ||
} | ||
|
||
private String extractDetectedXss(String inputAnswer, String sanitizedAnswer) { | ||
// inputAnswer와 sanitizedAnswer를 비교하여 공격이 감지된 부분을 추출합니다. | ||
StringBuilder detectedXss = new StringBuilder(); | ||
|
||
for (int i = 0; i < inputAnswer.length(); i++) { | ||
if (i >= sanitizedAnswer.length() || inputAnswer.charAt(i) != sanitizedAnswer.charAt(i)) { | ||
detectedXss.append(inputAnswer.charAt(i)); | ||
} | ||
} | ||
|
||
return detectedXss.toString(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...r/Recruit-Common/src/main/java/com/econovation/recruitcommon/annotation/XssProtected.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.econovation.recruitcommon.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Target({ElementType.METHOD, ElementType.FIELD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface XssProtected { | ||
} |
This file contains 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
7 changes: 7 additions & 0 deletions
7
...ommon/src/main/java/com/econovation/recruitcommon/exception/XssScriptAttackException.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.econovation.recruitcommon.exception; | ||
|
||
public class XssScriptAttackException extends RecruitCodeException { | ||
|
||
public static final RecruitCodeException EXCEPTION = new XssScriptAttackException(); | ||
private XssScriptAttackException() {super(GlobalErrorCode.XSS_SCRIPT_ATTACK);} | ||
} |
1 change: 1 addition & 0 deletions
1
...in/src/main/java/com/econovation/recruitdomain/domains/applicant/dto/BlockRequestDto.java
This file contains 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
This file contains 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