From 6076c342f8a0611466573fc89dfac6bfa01e89fc Mon Sep 17 00:00:00 2001 From: Sosthene Date: Sun, 15 Jun 2025 22:12:22 +0200 Subject: [PATCH] [bug] Do not request keys when we are not in the role in `decryptAttribute` --- src/services/service.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/services/service.ts b/src/services/service.ts index 208061e..a2cd2cc 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -1049,9 +1049,26 @@ export default class Services { return null; } let key = state.keys[attribute]; + const pairingProcessId = this.getPairingProcessId(); // If key is missing, request an update and then retry if (!key) { + const roles = state.roles; + let hasAccess = false; + // If we're not supposed to have access to this attribute, ignore + for (const role of Object.values(roles)) { + if (role.validation_rules.includes(attribute)) { + if (role.members.includes(pairingProcessId)) { + // We have access to this attribute + hasAccess = true; + break; + } + } + } + + if (!hasAccess) return null; + + // We should have the key, so we're going to ask other members for it await this.requestDataFromPeers(processId, [state.state_id], [state.roles]); const maxRetries = 5; @@ -1291,7 +1308,6 @@ export default class Services { await this.sendCommitMessage(JSON.stringify(content)); }, 1000) } - public getRoles(process: Process): Record | null { const lastCommitedState = this.getLastCommitedState(process); @@ -1358,7 +1374,6 @@ export default class Services { public async requestDataFromPeers(processId: string, stateIds: string[], roles: Record[]) { console.log('Requesting data from peers'); - console.log(roles); const membersList = this.getAllMembers(); try { const res = this.sdkClient.request_data(processId, stateIds, roles, membersList);