Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: secure allowance creationby including protocol information #2930

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/components/Enable/WeblnEnable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Container from "@components/Container";
import PublisherCard from "@components/PublisherCard";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import Alert from "~/app/components/Alert";
import ScreenHeader from "~/app/components/ScreenHeader";
import toast from "~/app/components/Toast";
import { USER_REJECTED_ERROR } from "~/common/constants";
Expand All @@ -15,6 +16,7 @@ type Props = {
};
function WeblnEnableComponent(props: Props) {
const [loading, setLoading] = useState(false);
const hasHttp = props.origin.domain.startsWith("http://");
const { t } = useTranslation("translation", {
keyPrefix: "webln_enable",
});
Expand Down Expand Up @@ -62,6 +64,14 @@ function WeblnEnableComponent(props: Props) {
isSmall={false}
/>

<div className="pt-3">
{hasHttp && (
<Alert type="warn">
⚠️ you are connecting to a unsecure domain
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
</Alert>
)}
</div>

<div className="dark:text-white pt-6">
<p className="mb-2">{tCommon("enable.allow")}</p>

Expand All @@ -75,6 +85,7 @@ function WeblnEnableComponent(props: Props) {
</div>
</div>
</div>

<div className="text-center flex flex-col">
<ConfirmOrCancel
disabled={loading}
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export function getHostFromSender(sender: Sender) {
// from a privileged page, otherwise use MessageSender.url
// MessageSender.origin is more reliable as it is not spoofable by a
// compromised renderer.
if (sender.origin) return new URL(sender.origin).host;
else if (sender.url) return new URL(sender.url).host;
if (sender.origin) return sender.origin;
else if (sender.url) return new URL(sender.url).origin;
else return null;
}

Expand Down
31 changes: 19 additions & 12 deletions src/extension/background-script/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// import db from "../db";
// import state from "../state";
import db from "~/extension/background-script/db";
import state from "../state";

export type Migration = keyof typeof migrations;

/*

// TS does not want unused code.
// we need this for the next migration again

Expand All @@ -30,19 +28,28 @@ const setMigrated = (name: Migration): Promise<void> => {
return state.getState().saveToStorage();
};

*/

const migrations = {};
const migrations = {
migrateAllowanceDomainProtocol: async () => {
const allowances = await db.allowances.toArray();

allowances.forEach(async (allowances) => {
allowances.id &&
(await db.allowances.update(allowances.id, {
host: `https://${allowances.host}`,
}));
});
},
};

const migrate = async () => {
// going forward we can iterate through the the migrations object above and DRY this up:
// Object.keys(migrations).forEach((name: string) => {
// example:
//if (shouldMigrate("migratePermissionsWithoutAccountId")) {
// console.info("Running migration for: migratePermissionsWithoutAccountId");
// await migrations["migratePermissionsWithoutAccountId"]();
// await setMigrated("migratePermissionsWithoutAccountId");
//}
if (shouldMigrate("migrateAllowanceDomainProtocol")) {
console.info("Running migration for: migrateAllowanceDomainProtocol");
await migrations["migrateAllowanceDomainProtocol"]();
await setMigrated("migrateAllowanceDomainProtocol");
}
};

export default migrate;
Loading