From b76bb097f2df28edf05aba7563288b37e39f2ead Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 23 Nov 2021 14:55:40 -0600 Subject: [PATCH] Status: protect against infinite context loops --- app/soapbox/features/status/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/soapbox/features/status/index.js b/app/soapbox/features/status/index.js index fbb17bae6..9b143b604 100644 --- a/app/soapbox/features/status/index.js +++ b/app/soapbox/features/status/index.js @@ -80,7 +80,7 @@ const makeMapStateToProps = () => { let ancestorsIds = ImmutableOrderedSet(); let id = statusId; - while (id) { + while (id && !ancestorsIds.includes(id)) { ancestorsIds = ImmutableOrderedSet([id]).union(ancestorsIds); id = inReplyTos.get(id); } @@ -99,6 +99,10 @@ const makeMapStateToProps = () => { const id = ids.shift(); const replies = contextReplies.get(id); + if (descendantsIds.includes(id)) { + break; + } + if (statusId !== id) { descendantsIds = descendantsIds.union([id]); } @@ -119,8 +123,11 @@ const makeMapStateToProps = () => { let descendantsIds = ImmutableOrderedSet(); if (status) { - ancestorsIds = getAncestorsIds(state, { id: state.getIn(['contexts', 'inReplyTos', status.get('id')]) }); - descendantsIds = getDescendantsIds(state, { id: status.get('id') }); + const statusId = status.get('id'); + ancestorsIds = getAncestorsIds(state, { id: state.getIn(['contexts', 'inReplyTos', statusId]) }); + descendantsIds = getDescendantsIds(state, { id: statusId }); + ancestorsIds = ancestorsIds.delete(statusId).subtract(descendantsIds); + descendantsIds = descendantsIds.delete(statusId).subtract(ancestorsIds); } const soapbox = getSoapboxConfig(state);