MCPcopy
hub / github.com/ampproject/amphtml / checkOriginForSettingCookie

Function checkOriginForSettingCookie

src/cookies.js:242–262  ·  view source on GitHub ↗

* Throws if a given cookie should not be set on the given origin. * This is a defense-in-depth. Callers should never run into this. * * @param {!Window} win * @param {!Object} options * @param {string} name For the error message.

(win, options, name)

Source from the content-addressed store, hash-verified

240 * @param {string} name For the error message.
241 */
242function checkOriginForSettingCookie(win, options, name) {
243 if (options.allowOnProxyOrigin) {
244 userAssert(
245 !options.highestAvailableDomain,
246 'Could not support highestAvailable Domain on proxy origin, ' +
247 'specify domain explicitly'
248 );
249 return;
250 }
251 userAssert(
252 !isProxyOrigin(win.location.href),
253 `Should never attempt to set cookie on proxy origin: ${name}`
254 );
255 const current = parseUrlDeprecated(win.location.href).hostname.toLowerCase();
256 const proxy = parseUrlDeprecated(urls.cdn).hostname.toLowerCase();
257 userAssert(
258 !(current == proxy || endsWith(current, '.' + proxy)),
259 'Should never attempt to set cookie on proxy origin. (in depth check): ' +
260 name
261 );
262}
263
264/**
265 * Return a temporary cookie name for testing only

Callers 1

setCookieFunction · 0.85

Calls 4

userAssertFunction · 0.90
isProxyOriginFunction · 0.90
parseUrlDeprecatedFunction · 0.90
endsWithFunction · 0.90

Tested by

no test coverage detected