{"version":3,"file":"origin.mjs","sources":["../../../../src/auth/utils/origin.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n// a regular expression that validates the origin string to be any valid origin, and allowing local development localhost\nconst originRegex = /^(http:\\/\\/localhost(:\\d{1,5})?)|(https?:\\/\\/[a-z0-9-]+(\\.[a-z0-9-]+)*(:\\d{1,5})?)$/;\nexport const isValidOrigin = (origin) => {\n    const url = createUrlObjectOrUndefined(origin);\n    if (!url) {\n        return false;\n    }\n    if (url.protocol === 'http:' &&\n        url.hostname !== 'localhost' &&\n        url.hostname !== '127.0.0.1') {\n        // eslint-disable-next-line no-console\n        console.warn('HTTP origin detected. This is insecure and should only be used for local development.');\n    }\n    return url.protocol === 'http:' || url.protocol === 'https:';\n};\nexport const isSSLOrigin = (origin) => {\n    const url = createUrlObjectOrUndefined(origin);\n    if (!url) {\n        return false;\n    }\n    return url.protocol === 'https:';\n};\nconst createUrlObjectOrUndefined = (url) => {\n    if (!url) {\n        return undefined;\n    }\n    // we don't allow format such as `https://localhost:` (without the port number) which is valid in URL constructor\n    if (!originRegex.test(url)) {\n        return undefined;\n    }\n    // the `originRegex` ensured a string that can be parsed by URL constructor\n    return new URL(url);\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA,MAAM,WAAW,GAAG,qFAAqF;AAC7F,MAAC,aAAa,GAAG,CAAC,MAAM,KAAK;AACzC,IAAI,MAAM,GAAG,GAAG,0BAA0B,CAAC,MAAM,CAAC;AAClD,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO;AAChC,QAAQ,GAAG,CAAC,QAAQ,KAAK,WAAW;AACpC,QAAQ,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE;AACtC;AACA,QAAQ,OAAO,CAAC,IAAI,CAAC,uFAAuF,CAAC;AAC7G,IAAI;AACJ,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;AAChE;AACY,MAAC,WAAW,GAAG,CAAC,MAAM,KAAK;AACvC,IAAI,MAAM,GAAG,GAAG,0BAA0B,CAAC,MAAM,CAAC;AAClD,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ;AACpC;AACA,MAAM,0BAA0B,GAAG,CAAC,GAAG,KAAK;AAC5C,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,OAAO,SAAS;AACxB,IAAI;AACJ;AACA,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,SAAS;AACxB,IAAI;AACJ;AACA,IAAI,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC;AACvB,CAAC;;;;"}