[TIL] 211220

dev·2021년 12ė›” 20ėž
1

TIL

ëŠĐ록 ëģīęļ°
124/204
post-thumbnail

📝 ė˜Ī늘 한 ęēƒ

  1. Credentialed Request ė—ëŸŽ í•īęē°

📚 ë°°ėšī ęēƒ

1. 배폎

1) Heroku뗐 배폎

(1) Credentialed Request ė—ëŸŽ í•īęē° ðŸ”Ĩ

ė•žė„œ SharedArrayBuffer ė‚ŽėšĐęģž ęī€ë Ļí•ī ė—ëŸŽę°€ ë°œėƒí–ˆė„ 때 ė•„ëž˜ ė―”ë“œëĨž ėķ”ę°€í•˜ė—Ž í•īęē°í–ˆė—ˆë‹Ī.

app.use((req, res, next) => {
  res.header("Cross-Origin-Embedder-Policy", "require-corp");
  res.header("Cross-Origin-Opener-Policy", "same-origin");
  next();
});

ėī로 ėļí•ī github 프로필 ėīëŊļ맀氀 ëœĻė§€ ė•Šė•˜ë˜ ëŽļė œëŠ” img 태ę·ļ뗐 crossorigin ė†ė„ąė„ ėķ”ę°€í•˜ė—Ž í•īęē°í–ˆë‹Ī.

ę·ļ런데 AWSëĨž ėīėšĐ하ë Īęģ  ė„Īė •í•˜ëŠ” ęģžė •ė—ė„œ ėœ„ ė―”ë“œëĄœ ėļí•ī 또 ë‹Īė‹œ ėīëŊļ맀氀 ė œëŒ€ëĄœ 나ė˜Īė§€ ė•ŠėœžëĐīė„œ ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep 200 ė—ëŸŽę°€ ë°œėƒí–ˆë‹Ī.

SharedArrayBufferëĨž ė‚ŽėšĐ하ëĐīė„œë„ ë‹ĪëĨļ ėķœėē˜ëĄœëķ€í„° ëĶŽė†ŒėŠĪëĨž 가ė ļė˜Īęļ° ėœ„í•ī, ėē˜ėŒė—ëŠ” ė•„ëž˜ė™€ 같ėī cross-origin-resource-PolicyëĨž cross-originėœžëĄœ ė§€ė •í–ˆė§€ë§Œ, ė—ëŸŽëŠ” í•īęē°ë˜ė§€ ė•Šė•˜ë‹Ī.

app.use((req, res, next) => {
  res.header("Cross-Origin-Embedder-Policy", "require-corp");
  res.header("Cross-Origin-Opener-Policy", "same-origin");
  res.header("cross-origin-resource-Policy", "cross-origin");
  next();
});

ę·ļ럮던 ėĪ‘ ėī ęļ€ė„ 발ęēŽí–ˆë‹Ī.
CORS는 ė™œ ėī렇ęēŒ ėš°ëĶŽëĨž 힘ë“ĪęēŒ í•˜ëŠ”ęąļęđŒ? 렜ëŠĐ 너ëŽī ėž˜ė§€ėœžė…Ļ

ë‚ī가 ëģīë‚īęģ  ėžˆëŠ” ėš”ėē­ėī Credentialed Request띾는 ęēƒė„ ė•ŒęēŒ ëë‹Ī.
ę·ļ럮나, ė„ĪëŠ…ė„ ė°ļęģ í•ī ė‘ë‹ĩ í—Īë”ė— Access-Control-Allow-Credentials: trueëĨž ë„Ģė–īėĢžė—ˆė§€ë§Œ, ė—Žė „ížˆ í•īęē°ė€ ë˜ė§€ ė•Šė•˜ë‹Ī.

app.use((req, res, next) => {
  res.header("Cross-Origin-Embedder-Policy", "require-corp");
  res.header("Cross-Origin-Opener-Policy", "same-origin");
  res.header("cross-origin-resource-Policy", "cross-origin");
  res.header("Access-Control-Allow-Credentials", "true");
  next();
});

ę°œë°œėž 도ęĩŽ ë„ĪíŠļė›ŒíŽ íƒ­ė˜ ė‘ë‹ĩ í—Īë”ė—ė„œ ëŽļ렜 íƒ­ė— ë“Īė–ī가니ęđŒ ė•„ëž˜ė™€ ę°™ė€ ė•ˆë‚ī가 ë–īë‹Ī.
ë§ˆė§€ë§‰ ëŽļë‹Ļėī í•īęē° ë°Đëē•ėī 될 ėˆ˜ë„ ėžˆė„ ęą° 氙땄 ė‹œë„í•īëģīë Īęģ  í–ˆė§€ë§Œ, ėīëĶ„ėī 너ëŽī ëŽī턱대ęģ  ė ėšĐ하ëĐī ė•ˆë  ęēƒ ę°™ėī ėƒęēĻė„œ ęē€ėƒ‰í•īëīĪë‹Ī.

Because your site has the Cross-Origin Embedder Policy (COEP) enabled, each resource must specify a suitable Cross-Origin Resource Policy (CORP).
This behavior prevents a document from loading cross-origin resources which don’t explicitly grant permission to be loaded.

To solve this, add the following to the resource’ response header:

Cross-Origin-Resource-Policy: same-site
if the resource and your site are served from the same site.

Cross-Origin-Resource-Policy: cross-origin
if the resource is served from another location than your website. → ėē˜ėŒė— ė‹œë„í–ˆë˜ ë°Đëē•ėīė§€ë§Œ ėīęąļ로 í•īęē°ë˜ė§€ ė•Šė•˜ë‹Ī.
If you set this header, any website can embed this resource.

Alternatively, the document can use the variant:
Cross-Origin-Embedder-Policy: credentialless instead of require-corp.
It allows loading the resource, despite the missing CORP header, at the cost of requesting it without credentials like Cookies.

ę·ļëĶŽęģ  ėī ęļ€ė„ 발ęēŽí–ˆë‹Ī.
Cross-Origin-Embedder-Policy: credentialless

In this new COEP variant, cross-origin no-cors subresource requests would be sent without credentials.
Specific requests which require credentials can opt-into including them, at the cost of shifting the request’s mode to require a CORS check on the response.
This bifurcation between credentiallessness and CORS means either that servers don’t have browser-provided identifiers which could be used to personalize a response (see the isolation section below), or that they explicitly opt-in to exposing the response’s content to the requesting origin.

As an example, consider a developer who wishes to load an image into a context isolated in the way described above. The < img > element has a crossorigin attribute which allows developers to alter the outgoing request’s state. In this new mode, the following table describes the outgoing request’s properties in Fetch’s terms for various values:

ResourceRequest’s ModeRequest’s Credentials Mode includeCredentialsCOEP:unsafe-noneincludeCredentials COEP:credentialless
< img src="https://same-origin/" >same-originincludetruetrue
< img src="https://same-origin/" >same-originincludetruetrue
< img src="https://cross-origin/" >no-corsincludetruefalse
< img src="https://cross-origin/" crossorigin="anonymous" >no-corsomitfalsefalse
< img src="https://cross-origin/" crossorigin="use-credentials" >corsincludetruetrue

ėīëĨž ė°ļęģ í•ī ėžë‹Ļ Cross-Origin-Embedder-PolicyëĨž credentialless로 ė„Īė •í–ˆë‹Ī.
ę·ļëĶŽęģ  ėī로 ėļí•ī ëŽļė œę°€ 될 눘 ėžˆëŠ” ëķ€ëķ„ë“Ī, ė͉ 가ė ļė˜Ī는데 ėžęēĐ ėĶëŠ…ė„ í•„ėš”ëĄœ 하는 img(github 로ę·ļėļ userė˜ 프로필 ė‚Žė§„)ė—ëŠ” crossorigin="use-credentials" ė†ė„ąė„ ëķ€ė—Ží–ˆë‹Ī.

// server.js
app.use((req, res, next) => {
  res.header("Cross-Origin-Embedder-Policy", "credentialless");
  res.header("Cross-Origin-Opener-Policy", "same-origin");
  next();
});
//- header.pug & profile.pug
img(src=loggedInUser.avatarUrl, crossorigin="use-credentials").profile-img

드디ė–ī ėīëŊļ맀氀 ė •ėƒė ėœžëĄœ ëœĻ는 ęēƒė„ 확ėļ했ë‹Ī.

ėī렜 íŒŒėžė€ ė„œëē„ę°€ ė•„ë‹ˆëž AWS뗐 ė €ėžĨ되ęļ° ë•ŒëŽļ뗐 git pushëĨž í†ĩí•ī ė„œëē„ëĨž ėƒˆëĄœ ëđŒë“œí•ī도 íŒŒėžė€ ė§€ė›Œė§€ė§€ ė•ŠëŠ”ë‹Ī. ę·ļ럮나...


âœĻ ë‚īėž 할 ęēƒ

  1. ė—ëŸŽëŠ” ęģ„ė†ëœë‹Ī
profile
dev log

2ę°œė˜ 댓ęļ€

comment-user-thumbnail
2022년 6ė›” 3ėž

덕ëķ„뗐 ė—ëŸŽëĨž í•īęē°í–ˆėŠĩ니ë‹Ī.. ę°ė‚Ží•Đ니ë‹Ī..

ë‹ĩęļ€ ë‹Žęļ°
comment-user-thumbnail
2023년 2ė›” 16ėž

ę°ė‚Ží•Đ니ë‹Ī

ë‹ĩęļ€ ë‹Žęļ°