CORS Misconfiguration Vulnerability
CORS設定ミスの脆弱性
説明
CORSの不適切な設定とは、Webサーバー上でCross-Origin Resource Sharing(CORS)ポリシーが適切に構成されていない脆弱性を指します。これにより、許可されていないクロスオリジンリクエストの実行が可能になり、情報漏洩や機密データへの不正アクセスにつながる可能性があります。
以下は、さまざまな人気フレームワークにおける不正なCORS構成の例です。
CORS_ALLOWED_ORIGIN_REGEXES = [
r"*",
]
CORS_ALLOW_METHODS = [
"DELETE",
"GET",
"OPTIONS",
"PATCH",
"POST",
"PUT",
]
const express = require('express');
const cors = require('cors');
const app = express();
const ingredients = [];
app.use(cors({
origin: '*'
}));
app.get('/ingredients', (req, res) =>{
res.send(ingredients);
});
app.listen(6069);
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@RestController
class UserController {
@CrossOrigin(origins = "*")
@GetMapping("/users/{id}")
fun getUser(@PathVariable id: String): String {
// Fetch user data from the database based on the provided id
return "User with id $id"
}
}
推奨事項
CORSの不適切な設定による脆弱性を軽減するには、ベストプラクティスに従うことが重要です。これには、ワイルドカード(*)値を使用するのではなく、信頼できるオリジンのみを許可するようにAccess-Control-Allow-Originヘッダーを適切に構成することが含まれます。さらに、承認されたユーザーのみが機密リソースにアクセスできるように、適切な認証および認可メカニズムを実装することが不可欠です。CORS構成を定期的に監視および監査することで、潜在的な設定ミスや脆弱性を特定し、対処することができます。
以下は、CORSの安全な設定の例です。
CORS_ALLOWED_ORIGINS = [
"https://cross-origin-website.com",
"https://sub.cross-origin-website.com",
]
CORS_ALLOW_METHODS = [
"DELETE",
"GET",
"OPTIONS",
"PATCH",
"POST",
"PUT",
]
const express = require('express');
const cors = require('cors');
const app = express();
const ingredients = [];
app.use(cors({
origin: 'https://cross-origin-website.com'
}));
app.get('/ingredients', (req, res) =>{
res.send(ingredients);
});
app.listen(6069);
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@RestController
class UserController {
@CrossOrigin(origins = ["http://localhost:8080"]) // Replace with your allowed origin(s)
@GetMapping("/users/{id}")
fun getUser(@PathVariable id: String): String {
// Fetch user data from the database based on the provided id
return "User with id $id"
}
}
リンク
標準
- PCI_STANDARDS:
- REQ_2_2
- REQ_6_2
- REQ_6_3
- REQ_7_3
- REQ_8_3
- REQ_11_3
- HIPAA_CONTROLS:
- SECURITY221
- SECURITY212
- SECURITY213