[fix][views] apply the token owner's read right on the heatmap endpoint (24.05) - #7936
Open
ar2rsawseen wants to merge 1 commit into
Open
[fix][views] apply the token owner's read right on the heatmap endpoint (24.05)#7936ar2rsawseen wants to merge 1 commit into
ar2rsawseen wants to merge 1 commit into
Conversation
The countly-token branch of /o/actions resolves the target app from the caller supplied app_key and then served the data once the token itself verified. It never resolved the token to the member who created it, so that member's own rights were never consulted. Everywhere else a token acts as its owner: verify_return hands back the owner, and the usual validation loads that member and applies their rights, while the token's app and endpoint fields only narrow things further. This branch skipped that step, which left the optional app restriction as the only thing bounding which app could be read. A token saved without an app restriction is not narrowed at all, which is correct in itself, so nothing remained to bound the read. Load the owner and require a views read right on the app resolved from app_key, the way validateRead does for the api_key branch below it. The heatmap feature has been out of the product for over two years and this endpoint stays only so that a long-standing integration does not break, so this keeps the existing flow working: the dashboard mints its token scoped to the active app, and its owner holds the read right for that app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #7935 to release.24.05.
No test is added here: this branch has no
plugins/views/tests/heatmaps.js, the file is newer than 24.05.What
The
countly-tokenbranch of/o/actionsresolves the target app from the caller suppliedapp_key:and then served the data as soon as the token verified. The
ownerit gets back was never used for anything: the member was not loaded and no read right was checked, sogetHeatmapran withmatchQuery.aset to whatever app theapp_keynamed.Everywhere else a token acts as its owner.
verify_returnreturns the owner, thenvalidateUser/validateReadload that member and apply their real rights, while the token'sapp,endpointandttlfields only narrow it further. This branch skipped that step, which left the optional app restriction as the only thing bounding the read. A token saved without an app restriction is not narrowed at all, which is correct in itself, so nothing remained to bound it.Change
Load the token's owner and require a
viewsread right on the app resolved fromapp_key, mirroring whatvalidateRead(params, FEATURE_NAME, getHeatmap)already does for theapi_keybranch a few lines below.Compatibility
The heatmap feature has been out of the product for over two years and this endpoint stays only so a long-standing integration does not break, so the existing flow is preserved rather than tightened:
createToken("View heatmap", "/o/actions", true, countlyCommon.ACTIVE_APP_ID, 1800, ...)inplugins/views/frontend/public/javascripts/countly.views.js. Same call in every repo checked.verify_tokenis untouched: an empty app scope still means "not additionally restricted", which is correct on every path that applies the owner's rights.Verification
plugins/views/tests/heatmaps.jsgains a case that exercises thecountly-tokenbranch end to end: mint a token the way the dashboard does, send it in the header, and assert the heatmap rows still come back. That branch had no test coverage at all before, the existing cases all useapi_keyand go throughvalidateRead.node --checkand eslint clean on the changed files.