mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-01 02:12:26 +00:00
Allow anonymous session actors when checking login state
This commit is contained in:
1 parent
f6a3e8b2ae
commit
7985a481a4
2 files changed
+45
-9
No files matched your search
@@ -3499,11 +3499,25 @@ class Application {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionActorPubkey = this.normalizeHexPubkey(
|
const sessionActor = nostrClient?.sessionActor || null;
|
||||||
nostrClient?.sessionActor?.pubkey,
|
const sessionActorPubkey = this.normalizeHexPubkey(sessionActor?.pubkey);
|
||||||
);
|
|
||||||
if (sessionActorPubkey && sessionActorPubkey !== normalizedPubkey) {
|
if (sessionActorPubkey && sessionActorPubkey !== normalizedPubkey) {
|
||||||
return false;
|
const rawPrivateKey =
|
||||||
|
typeof sessionActor?.privateKey === "string"
|
||||||
|
? sessionActor.privateKey.trim()
|
||||||
|
: "";
|
||||||
|
const hasEmbeddedPrivateKey =
|
||||||
|
rawPrivateKey.length > 0 && HEX64_REGEX.test(rawPrivateKey);
|
||||||
|
|
||||||
|
const declaredSource =
|
||||||
|
typeof sessionActor?.source === "string"
|
||||||
|
? sessionActor.source.trim()
|
||||||
|
: "";
|
||||||
|
const isPersisted = sessionActor?.persisted === true;
|
||||||
|
|
||||||
|
if (!hasEmbeddedPrivateKey || declaredSource || isPersisted) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ test("isUserLoggedIn guards against mismatched nostrClient state", () => {
|
|||||||
const previousSessionActor = nostrClient.sessionActor;
|
const previousSessionActor = nostrClient.sessionActor;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pubkey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
const pubkey = "a".repeat(64);
|
||||||
nostrClient.pubkey = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
|
nostrClient.pubkey = "b".repeat(64);
|
||||||
nostrClient.sessionActor = { pubkey };
|
nostrClient.sessionActor = { pubkey };
|
||||||
|
|
||||||
const app = createTestApp(pubkey);
|
const app = createTestApp(pubkey);
|
||||||
@@ -90,15 +90,37 @@ test("isUserLoggedIn guards against mismatched nostrClient state", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isUserLoggedIn rejects mismatched session actor pubkeys", () => {
|
test("isUserLoggedIn ignores anonymous session actor mismatches", () => {
|
||||||
const previousPubkey = nostrClient.pubkey;
|
const previousPubkey = nostrClient.pubkey;
|
||||||
const previousSessionActor = nostrClient.sessionActor;
|
const previousSessionActor = nostrClient.sessionActor;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pubkey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
const pubkey = "c".repeat(64);
|
||||||
nostrClient.pubkey = pubkey;
|
nostrClient.pubkey = pubkey;
|
||||||
nostrClient.sessionActor = {
|
nostrClient.sessionActor = {
|
||||||
pubkey: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
pubkey: "d".repeat(64),
|
||||||
|
privateKey: "e".repeat(64),
|
||||||
|
createdAt: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const app = createTestApp(pubkey);
|
||||||
|
assert.equal(app.isUserLoggedIn(), true);
|
||||||
|
} finally {
|
||||||
|
nostrClient.pubkey = previousPubkey;
|
||||||
|
nostrClient.sessionActor = previousSessionActor;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("isUserLoggedIn rejects mismatched managed session actors", () => {
|
||||||
|
const previousPubkey = nostrClient.pubkey;
|
||||||
|
const previousSessionActor = nostrClient.sessionActor;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const pubkey = "f".repeat(64);
|
||||||
|
nostrClient.pubkey = pubkey;
|
||||||
|
nostrClient.sessionActor = {
|
||||||
|
pubkey: "0".repeat(64),
|
||||||
|
source: "nsec",
|
||||||
};
|
};
|
||||||
|
|
||||||
const app = createTestApp(pubkey);
|
const app = createTestApp(pubkey);
|
||||||
|
|||||||
Reference in new issue
Block a user