언어/Java

pathParam url slash 이슈.

xzpluszone 2021. 9. 24. 13:35

#### pathParam url slash 이슈.
tomcat에서 url의 /가 encode된 값을 decode하는데 이때,
tomcat에서는 기본적으로 false가 되어 있다.


tomcat-embed-core쪽
```java
package org.apache.tomcat.util.buf;

import java.io.ByteArrayOutputStream;
import java.io.CharConversionException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.apache.tomcat.util.res.StringManager;

/**
 *  All URL decoding happens here. This way we can reuse, review, optimize
 *  without adding complexity to the buffers.
 *
 *  The conversion will modify the original buffer.
 *
 *  @author Costin Manolache
 */
public final class UDecoder {

    private static final StringManager sm = StringManager.getManager(UDecoder.class);

    public static final boolean ALLOW_ENCODED_SLASH =
        Boolean.parseBoolean(System.getProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "false"));
```

tomcat configure 수정을 변경해야 하는데 하지만,
apache쪽에서 보안 이슈가 있는 거 같다.

ref : https://backstage.forgerock.com/knowledge/kb/article/a59558448

결론 : 
configure를 변경하여 적용은 할 수 있지만.. PathParam에서 왠만하면 / 를 사용하지 말자.

1. 일반적인 Param에는 /를 사용가능하다.
2. body절에 encode된 문자열이 들어가면 된다.

```json
{
"network_bw_name": "DPG_251%2f",
}

```

실제 어떤 application 처리 시
데이터 가져올 때, encode로 된 정보도 주기때문에 보낸 body도 encode로 보낸거면 상관없다.
```bash
network Mapping : VDS_01 / DPG_251%2f

Network dvs Find key : dvportgroup-63 / type : earlyBinding / name : DPG_251%2f
Find NetworkId : DPG_251%2f
```