Skip to content

Commit

Permalink
removes integrity check
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed May 23, 2023
1 parent 60d34f4 commit 38b8c0e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 102 deletions.
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@metamask/obs-store": "^8.1.0",
"@toruslabs/http-helpers": "^4.0.0",
"@toruslabs/openlogin-jrpc": "^4.4.0",
"create-hash": "^1.2.0",
"end-of-stream": "^1.4.4",
"eth-rpc-errors": "^4.0.3",
"events": "^3.3.0",
Expand Down
34 changes: 2 additions & 32 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import deepmerge from "lodash.merge";
import configuration from "./config";
import { documentReady, handleStream, htmlToElement, runOnLoad } from "./embedUtils";
import TorusInpageProvider from "./inpage-provider";
import generateIntegrity from "./integrity";
import {
BUTTON_POSITION,
BUTTON_POSITION_TYPE,
Expand Down Expand Up @@ -47,10 +46,6 @@ const defaultVerifiers = {
[LOGIN_PROVIDER.DISCORD]: true,
};

const iframeIntegrity = "sha384-5wfQNApq4YIunQu3JVyIfoWQHdz5824c+mHr1WOMddVX9N+d6ErcA25MCuLSLeQH";

const expectedCacheControlHeader = "max-age=3600";

const UNSAFE_METHODS = [
"eth_sendTransaction",
"eth_signTypedData",
Expand All @@ -68,7 +63,7 @@ const UNSAFE_METHODS = [
try {
if (typeof document === "undefined") return;
const torusIframeHtml = document.createElement("link");
const { torusUrl } = await getTorusUrl("production", { check: false, hash: iframeIntegrity, version: "" });
const { torusUrl } = await getTorusUrl("production", { version: "" });
torusIframeHtml.href = `${torusUrl}/popup`;
torusIframeHtml.crossOrigin = "anonymous";
torusIframeHtml.type = "text/html";
Expand Down Expand Up @@ -174,8 +169,6 @@ class Torus {
loginConfig = {},
showTorusButton = true,
integrity = {
check: false,
hash: iframeIntegrity,
version: "",
},
whiteLabel,
Expand Down Expand Up @@ -268,30 +261,7 @@ class Torus {
});
};

if (buildEnv === "production" && integrity.check) {
// hacky solution to check for iframe integrity
const fetchUrl = `${torusUrl}/popup`;
const resp = await fetch(fetchUrl, { cache: "reload" });
if (resp.headers.get("Cache-Control") !== expectedCacheControlHeader) {
throw new Error(`Unexpected Cache-Control headers, got ${resp.headers.get("Cache-Control")}`);
}
const response = await resp.text();
const calculatedIntegrity = generateIntegrity(
{
algorithms: ["sha384"],
},
response
);
log.info(calculatedIntegrity, "integrity");
if (calculatedIntegrity === integrity.hash) {
await handleSetup();
} else {
this.clearInit();
throw new Error("Integrity check failed");
}
} else {
await handleSetup();
}
await handleSetup();
return undefined;
}

Expand Down
44 changes: 0 additions & 44 deletions src/integrity.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { JRPCId, JRPCMiddleware, JRPCRequest, JRPCVersion, SafeEventEmitter } from "@toruslabs/openlogin-jrpc";
import createHash from "create-hash";
import type { Duplex } from "readable-stream";

export const LOGIN_PROVIDER = {
Expand Down Expand Up @@ -77,17 +76,6 @@ export interface IPaymentProvider {
sell?: boolean;
}

export interface IHashAlgorithmOptions {
algorithms?: createHash.algorithm[];
delimiter?: string;
full?: boolean;
}

export interface SRI {
hashes: Record<createHash.algorithm, string>;
integrity?: string;
}

export const BUTTON_POSITION = {
BOTTOM_LEFT: "bottom-left",
TOP_LEFT: "top-left",
Expand Down Expand Up @@ -492,17 +480,6 @@ export interface ThemeParams {
}

export interface IntegrityParams {
/**
* Whether to check for integrity.
* Defaults to false
* @defaultValue false
*/
check: boolean;
/**
* if check is true, hash must be provided. The SRI sha-384 integrity hash
* {@link https://www.srihash.org/ | SRI Hash}
*/
hash?: string;
/**
* Version of torus-website to load
*/
Expand Down

0 comments on commit 38b8c0e

Please sign in to comment.