Skip to content

Commit 754f90f

Browse files
committed
docs: update contents
1 parent 6175bab commit 754f90f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

_posts/spring/2022-12-05-spring-boot-cors-error.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ CORS는 교차 출처 요청을 허용하는 것이 안전한지 아닌지를
1313

1414
CORS의 사양은 원래 W3C 권고안으로 배포되었으나 해당 문서는 쓸모없어진(obsolete) 상태이다. 현재 CORS를 재정의하면서 활발히 유지보수된 사양은 [WHATWG](https://ko.wikipedia.org/wiki/WHATWG)의 Fetch Living Standard이다.
1515

16+
![cors-url](/assets/img/2022-12-05-spring-boot-cors-error/cors-url.png)
17+
1618
## 2. CORS 동작 원리
1719

1820
![cors-operation](/assets/img/2022-12-05-spring-boot-cors-error/cors-operation.png)
@@ -22,6 +24,14 @@ CORS의 사양은 원래 W3C 권고안으로 배포되었으나 해당 문서는
2224
### 1) Configuration 설정
2325
Global하게 적용하는 방법이다.
2426

27+
> 서버측에서 ACAO 헤더의 값을 와일드카드(`*`)로 설정하면 출처가 다른 모든 웹 사이트에서 접근할 수 있기 때문에 보안에 취약하다.
28+
29+
```text
30+
HTTP/1.1 200 OK
31+
Access-Control-Allow-Origin: *
32+
...
33+
```
34+
2535
* WebConfig.java
2636

2737
```java
@@ -35,7 +45,7 @@ public class WebConfig implements WebMvcConfigurer {
3545
@Override
3646
public void addCorsMappings(CorsRegistry corsRegistry) {
3747
corsRegistry.addMapping("/**") // CORS를 적용할 URL패턴 정의
38-
.allowedOrigins("*") // 자원 공유를 허락할 Origin 지정
48+
.allowedOrigins("http://front-server.com") // 자원 공유를 허락할 Origin 지정
3949
.allowedMethods("GET", "POST") // 허용할 HTTP method 지정
4050
.maxAge(3000); // 설정 시간만큼 pre-flight 리퀘스트 캐싱
4151
}
@@ -57,7 +67,7 @@ import org.springframework.web.bind.annotation.RestController;
5767
@Slf4j
5868
@RequiredArgsConstructor
5969
@RestController
60-
@CrossOrigin(origins = "*", allowedHeaders = "*")
70+
@CrossOrigin(origins = "http://front-server.com")
6171
@RequestMapping(path = "/board")
6272
public class Controller {
6373

@@ -78,7 +88,7 @@ import org.springframework.web.bind.annotation.*;
7888
@RequestMapping(path = "/board")
7989
public class Controller {
8090

81-
@CrossOrigin(origins = "*", allowedHeaders = "*")
91+
@CrossOrigin(origins = "http://front-server.com")
8292
@GetMapping(path = "/{id}")
8393
public ResponseEntity<String> find(@PathVariable("id") String id) {
8494
...
@@ -89,4 +99,6 @@ public class Controller {
8999

90100
## [출처 및 참고]
91101
* [https://ko.wikipedia.org/wiki/교차_출처_리소스_공유](https://ko.wikipedia.org/wiki/교차_출처_리소스_공유)
102+
* [https://www.bugbountyclub.com/pentestgym/view/60](https://www.bugbountyclub.com/pentestgym/view/60)
103+
* [https://docs.tosspayments.com/resources/glossary/cors](https://docs.tosspayments.com/resources/glossary/cors)
92104
* [https://dev-pengun.tistory.com/entry/Spring-Boot-CORS-%EC%84%A4%EC%A0%95%ED%95%98%EA%B8%B0#1.%20CORS%EB%9E%80?](https://dev-pengun.tistory.com/entry/Spring-Boot-CORS-%EC%84%A4%EC%A0%95%ED%95%98%EA%B8%B0#1.%20CORS%EB%9E%80?)
Loading

0 commit comments

Comments
 (0)