diff --git a/src/inabox/amp-inabox.js b/src/inabox/amp-inabox.js index ef2d525c1b92..885c9652a8c5 100644 --- a/src/inabox/amp-inabox.js +++ b/src/inabox/amp-inabox.js @@ -48,6 +48,7 @@ import {installViewerServiceForDoc} from '../service/viewer-impl'; import {internalRuntimeVersion} from '../internal-version'; import {isExperimentOn} from '../experiments'; import {maybeValidate} from '../validator-integration'; +import {rejectServicePromiseForDoc} from '../service'; import {startupChunk} from '../chunk'; import {stubElementsForDoc} from '../service/custom-element-registry'; @@ -93,6 +94,9 @@ startupChunk(self.document, function initial() { fullCss, () => { startupChunk(self.document, function services() { + // For security, storage is not supported in inabox. + // Fail early with console errors for any attempt of access. + unsupportedService(ampdoc, 'storage'); // Core services. installRuntimeServices(self); fontStylesheetTimeout(self); @@ -150,3 +154,15 @@ self.document.documentElement.setAttribute( 'amp-version', internalRuntimeVersion() ); + +/** + * @param {!../service/ampdoc-impl.AmpDoc} ampdoc + * @param {string} name + */ +function unsupportedService(ampdoc, name) { + rejectServicePromiseForDoc( + ampdoc, + name, + new Error('Un-supported service: ' + name) + ); +} diff --git a/src/service/core-services.js b/src/service/core-services.js index 9ee155de8a0e..682570ae7686 100644 --- a/src/service/core-services.js +++ b/src/service/core-services.js @@ -92,7 +92,10 @@ export function installAmpdocServices(ampdoc, opt_initParams, opt_inabox) { installUrlReplacementsServiceForDoc(ampdoc); installActionServiceForDoc(ampdoc); installStandardActionsForDoc(ampdoc); - installStorageServiceForDoc(ampdoc); + if (!opt_inabox) { + // For security, Storage is not supported in inabox. + installStorageServiceForDoc(ampdoc); + } installGlobalNavigationHandlerForDoc(ampdoc); installGlobalSubmitListenerForDoc(ampdoc); }