Skip to content

xss-stage/xss-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

49 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

xss-stage๋Š” ์ด๋ฏธ ๋‹ค์–‘ํ•œ xss๊ณต๊ฒฉ์„ ํ•„ํ„ฐ๋งํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์ง€๋งŒ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋งˆ๋‹ค ์ ์šฉ๋ฐฉ์‹์ด ์ œ๊ฐ๊ฐ์ด๋ฉฐ, ์—ฌ๋Ÿฌ xss ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ(์˜ˆ : json์„ ํ•„ํ„ฐ๋ง ํ•ด์ฃผ์ง€ ๋ชปํ•˜๋Š” lucy-xss ์™€ json์„ ํ•„ํ„ฐ๋งํ•ด์ฃผ๋Š” ๋‹ค๋ฅธ xss ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด์•ผํ• ๋•Œ)์—์„œ ๋‹ค์–‘ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ•จ๊ป˜ ์ ์šฉํ•˜๊ธฐ ์–ด๋ ค์šด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ณ  ์ผ๊ด€๋œ ๋ฐฉ์‹์œผ๋กœ ์ ์šฉํ•˜๋Š”๊ฒƒ์„ ๋•๊ธฐ ์œ„ํ•ด ํƒ„์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

Press Star

Hits made with love
needed jdk version
api-version api-version api-version

Overview

xss-stage๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ์ผ๊ด€์ ์ด๊ณ  ์‰ฌ์šด ์ ์šฉ ๋ฐฉ์‹ - ๊ฐ ์ƒํ™ฉ์— ํšจ์œจ์ ์ธ ๋‹ค์–‘ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ผ๊ด€๋œ ์ ์šฉ๋ฐฉ์‹์œผ๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. ์‰ฌ์šด ํ™•์žฅ๊ณผ ์ปค์Šคํ…€ - XssFiltering ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ  ์Šคํ”„๋ง ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•˜๋ฉด, ์ด ๊ตฌํ˜„์ฒด๋ฅผ ์ด์šฉํ•ด ๋Œ€์ƒ์„ ํ•„ํ„ฐ๋ง ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  3. ์„ ํƒ์ ์ธ Xss filtering - ๊ผญ ํ•„์š”ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ์™€ url๋งŒ Xss filtering ๋Œ€์ƒ์œผ๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  4. ๋‚ฎ์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์˜์กด์„ฑ - Xss core์—์„œ ์ œ๊ณตํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์˜์กด์„ฑ์„ ์ค„์—ฌ, ์–ธ์ œ๋“ ์ง€ ๊ตฌ์ฒด์ ์ธ ํ•„ํ„ฐ๋ง ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ต์ฒดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  5. ๊ฒ€์ฆ๋œ filtering ๊ตฌํ˜„์ฒด๋“ค - Xss stage ํ™•์žฅ์ธ xss-extension-string, xss-extension-json๋Š” ๊ฐ๊ฐ navercorp-lucy, jackson์„ ์‚ฌ์šฉํ•ด ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  6. ์š”์ฒญ์—์„œ ์ง„ํ–‰๋˜๋Š” xss filtering - Xss stage๋Š” ์š”์ฒญ์‹œ์— xss filtering์ด ์ง„ํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ์‘๋‹ต์ด ๋” ๋งŽ์€ ์ƒํ™ฉ์—์„œ ๋” ํšจ์œจ์ ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  7. ํ•œ๊ณณ์—์„œ ๊ด€๋ฆฌํ•˜๋Š” xss filtering ์ •์ฑ… - ์ •์ฑ… ๊ด€๋ฆฌ ํŒŒํŠธ์—์„œ ๊ตฌํ˜„ํ•œ XssFiltering๊ตฌํ˜„์ฒด๋ฅผ ๋“ฑ๋กํ•˜๊ณ , ๋‹ค๋ฅธ ํŒŒํŠธ์—์„œ @Xss ์–ด๋…ธํ…Œ์ด์…˜์„ ํ†ตํ•ด ๊ตฌํ˜„์ฒด๋ฅผ ์„ ํƒํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•œ ๊ณณ์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ „์ฒด์ ์ธ Xss filtering ์ •์ฑ…์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Extensions

core : xss-core
string-extension : xss-extension-string - naver์˜ lucy-xss ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
json-extension : xss-extension-json - jackson์˜ databind๋ฅผ ์‚ฌ์šฉํ•ด ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

Downloads

๋‹ค์šด๋กœ๋“œ์— ๊ด€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์—ฌ๊ธฐ๋ฅผ ์ฐธ์กฐํ•ด์ฃผ์„ธ์š”.

Usage

xss-stage์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐํŽ˜์ด์Šค์™€ ํ™•์žฅ๋ฒ•์€ ๋ชจ๋‘ xss-core ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์ž‘์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
Custom Xss Filter๊ฐ€ ํ•„์š”ํ•œ ์ƒํ™ฉ์ด ์•„๋‹ˆ๋ผ๋ฉด, ๋‹ค์Œ ์ธํ„ฐํŽ˜์ด์Šค๋กœ Xss-filtering์„ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋งŒ์•ฝ Custom Xss Filter๊ฐ€ ํ•„์š”ํ•˜๋‹ค๋ฉด, ์ด ๋‹ค์Œ ๋ชฉ์ฐจ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

@XssFiltering : ๋ฉ”์†Œ๋“œ์— ๋งˆํ‚น๊ฐ€๋Šฅํ•˜๋ฉฐ, ๋งˆํ‚น๋œ ๋ฉ”์†Œ๋“œ๋Š” XssFiltering์˜ ๋Œ€์ƒ์ด ๋ฉ๋‹ˆ๋‹ค.
@Xss : @XssFiltering์ด ๋งˆํ‚น๋œ ๋ฉ”์†Œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ์— ๋งˆํ‚น๊ฐ€๋Šฅํ•˜๋ฉฐ, ๋งˆํ‚น๋œ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋Œ€์ƒ์œผ๋กœ Xss filtering์ด ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค. @Xss๋Š” String filterName() ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ–๊ณ ์žˆ์œผ๋ฉฐ, ์ด ๋ฉ”์†Œ๋“œ์— ๊ฐ’์„ ์„ค์ •ํ•˜๋Š”๊ฒƒ์œผ๋กœ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํ•„ํ„ฐ๋งํ• ๋•Œ ์‚ฌ์šฉํ•  XssFilter๋ฅผ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. filterName()์€ value()์™€ ๋™์ผํ•˜๋ฉฐ, ์ด ๋‘˜ ๋ชจ๋‘ ์ƒ๋žต๋œ๋‹ค๋ฉด, ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ํด๋ž˜์Šค๋ช…์„ ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•œ ๊ฐ’์œผ๋กœ XssFilter๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์€ ์‹ค์ œ ์‚ฌ์šฉ์˜ˆ์‹œ ์ž…๋‹ˆ๋‹ค.

@RestController
public class Example{
  
    @XssFiltering // ์ด ์–ด๋…ธํ…Œ์ด์…˜์ด ๋งˆํ‚น๋œ ๋ฉ”์†Œ๋“œ๋Š” XssFiltering์˜ ๋Œ€์ƒ์ด ๋ฉ๋‹ˆ๋‹ค.
    @GetMapping("/example")
    public Object helloworld(@Xss String param1, @Xss("json") SomeObject param2, @Xss("string") String param3, String param4){
        // @XssFiltering ์–ด๋…ธํ…Œ์ด์…˜์ด ๋งˆํ‚น๋œ ๋ฉ”์†Œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ์— @Xss ์–ด๋…ธํ…Œ์ด์…˜์„ ๋งˆํ‚นํ•จ์œผ๋กœ์จ Xss safeํ•œ ๊ฐ์ฒด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
        // @Xss์˜ value()์— ์–ด๋– ํ•œ ๊ฐ’๋„ ๋“ค์–ด๊ฐ€์ง€ ์•Š๋Š”๋‹ค๋ฉด, ๋งˆํ‚น๋œ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ํด๋ž˜์Šค ์ด๋ฆ„์„ ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•œ ๊ฐ’์ด ๋ฉ๋‹ˆ๋‹ค.
        // @Xss์˜ value()์— ๊ฐ’์„ ๋„ฃ์Œ์œผ๋กœ์จ, ์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํ•„ํ„ฐ๋ง ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•  XssFilter ๊ตฌํ˜„์ฒด๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
        // @Xss์— ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ’์€ xss-extension ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.
        ...
    }
  
}

Extension

XssCore์— CustomFilter๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์„ ํ†ตํ•ด ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. org.stage.xss.core.spi.XssFilter ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.
  2. ํ•ด๋‹น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์Šคํ”„๋ง ๋นˆ์œผ๋กœ ๋“ฑ๋ก์‹œํ‚จ๋‹ค.

๋‹ค์Œ์€ XssFilter์ธํ„ฐํŽ˜์ด์Šค ์ž…๋‹ˆ๋‹ค.

package org.stage.xss.core.spi;

/**
 * ์ด ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ตฌํ˜„์ฒด๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌ๋ฐ›์•„ Xss-safe ํ•œ ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•ด์•ผํ•จ.
 *
 * @since 0.1
 * @author devxb
 */
public interface XssFilter{

    /**
     * XssFilter ๊ตฌํ˜„์ฒด์˜ ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•จ. <br>
     * ์ด ์ด๋ฆ„์€ Xss Filtering ๋Œ€์ƒ์„ ์‹๋ณ„ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋จ. {@link org.stage.xss.core.meta.Xss} <br>
     *
     * @return String XssFilter ๊ตฌํ˜„์ฒด์˜ ์˜ ์ด๋ฆ„
     */
    String getFilterName();

    /**
     * ํŒŒ๋ผ๋ฏธํ„ฐ 'dirty' ์™€ 'cast' ๋ฅผ ์ธ์ž๋กœ ๋ฐ›๊ณ , <br>
     * 'dirty' ๋ฅผ Xss-safe ํ•œ ์ƒํƒœ๋กœ ํ•„ํ„ฐ๋ง ํ•œ ๊ฒฐ๊ณผ๋ฅผ 'cast' ํƒ€์ž…์œผ๋กœ ๋ฐ˜ํ™˜ํ•จ.
     *
     * @param dirty Xss-safe ํ•œ ์ƒํƒœ๋กœ ํ•„ํ„ฐ๋ง ํ•  ๋Œ€์ƒ.
     * @param cast Xss-safe ํ•œ ๊ฐ์ฒด๊ฐ€ ๋ฐ˜ํ™˜๋  ํƒ€์ž….
     * @return Xss-safe ํ•œ ๊ฐ์ฒด
     * @param <P> ๋ฐ˜ํ™˜ ๋  ํƒ€์ž…
     */
    <P> P doFilter(Object dirty, Class<P> cast);

}

getFilterName()์€ @Xss(value = ?)์˜ ? ์™€ ๋งค์นญ๋˜๋ฉฐ, xss-core๋Š” ?์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ˜ํ™˜๊ฐ’์€ ๊ฐ–๊ณ ์žˆ๋Š” XssFilter๋ฅผ ์ฐพ์•„ filtering์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.