MCPcopy Create free account
hub / github.com/ampproject/amphtml / assertSource_

Method assertSource_

extensions/amp-iframe/0.1/amp-iframe.js:133–167  ·  view source on GitHub ↗

* @param {string} src * @param {string} containerSrc * @param {string} sandbox * @return {string} * @private

(src, containerSrc, sandbox = '')

Source from the content-addressed store, hash-verified

131 * @private
132 */
133 assertSource_(src, containerSrc, sandbox = '') {
134 const {element} = this;
135 const urlService = Services.urlForDoc(element);
136 const url = urlService.parse(src);
137 const {hostname, origin, protocol} = url;
138 // Some of these can be easily circumvented with redirects.
139 // Checks are mostly there to prevent people easily do something
140 // they did not mean to.
141 userAssert(
142 urlService.isSecure(src) || protocol == 'data:',
143 'Invalid <amp-iframe> src. Must start with https://. Found %s',
144 element
145 );
146 const containerUrl = urlService.parse(containerSrc);
147 userAssert(
148 !this.sandboxContainsToken_(sandbox, 'allow-same-origin') ||
149 (origin != containerUrl.origin && protocol != 'data:'),
150 'Origin of <amp-iframe> must not be equal to container %s' +
151 ' if allow-same-origin is set. See https://github.com/ampproject/' +
152 'amphtml/blob/main/docs/spec/amp-iframe-origin-policy.md for details.',
153 element
154 );
155 userAssert(
156 !(
157 endsWith(hostname, `.${urls.thirdPartyFrameHost}`) ||
158 // eslint-disable-next-line local/no-forbidden-terms
159 endsWith(hostname, '.ampproject.org')
160 ),
161 'amp-iframe does not allow embedding of frames from ' +
162 // eslint-disable-next-line local/no-forbidden-terms
163 'ampproject.*: %s',
164 src
165 );
166 return src;
167 }
168
169 /** @private */
170 assertPosition_() {

Callers 3

buildCallbackMethod · 0.95
test-amp-iframe.jsFile · 0.45

Calls 5

sandboxContainsToken_Method · 0.95
userAssertFunction · 0.90
endsWithFunction · 0.90
isSecureMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected