-
-
Notifications
You must be signed in to change notification settings - Fork 479
Fix attachment upload from custom widget with ACL #1512
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,9 +166,11 @@ export async function addRequestUser( | |
if (auth) { | ||
const tokens = options.gristServer.getAccessTokens(); | ||
const token = await tokens.verify(auth); | ||
const userId = token.userId; | ||
const user = await dbManager.getUser(userId); | ||
mreq.accessToken = token; | ||
// Once an accessToken is supplied, we don't consider anything else. | ||
// User is treated as anonymous apart from having an accessToken. | ||
mreq.user = user; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this safe? Could this potentially grant access to material beyond the specific document? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say that, this is safe as long as the party with access to the provided token is trusted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I think I understand the concern you raise with that question. It may be possible to access (or update) a another document from a custom widget linked to a document with read (and write) access. I have the feeling that if this fix "only" reinforce that vulnerability but it does not create it. I looked at the existing test suite, I remember some related to access limitations but I can't remember if any exist on cross document access limitation/validation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I tested this and I get a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repository with tests https://github.com/guillett/test-grist-access/blob/main/pages/index.js (Sorry I did not added a test in grist-core test suite) |
||
mreq.userId = userId; | ||
authDone = true; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2376,6 +2376,14 @@ export class GranularAccess implements GranularAccessForBundle { | |
this._pruneColumns(action, permInfo, tableId, accessCheck); | ||
} | ||
|
||
private async _checkAttachmentAccess(docSession: OptDocSession, attId: number) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you talk me through what this fixes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It fixes one specific situation. When a file is not attached to any cell yet. Without this fix, the access is denied. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the lazy |
||
const list = await this._docStorage.findAttachmentReferences(attId); | ||
if (list.length) { | ||
return await this.findAttachmentCellForUser(docSession, attId); | ||
} | ||
return await this.isAttachmentUploadedByUser(docSession, attId); | ||
} | ||
|
||
/** | ||
* Take a look at the DocAction and see if it might allow the user to | ||
* introduce attachment ids into a cell. If so, make sure the user | ||
|
@@ -2385,8 +2393,7 @@ export class GranularAccess implements GranularAccessForBundle { | |
const {docSession} = cursor; | ||
const attIds = await this._gatherAttachmentChanges(cursor); | ||
for (const attId of attIds) { | ||
if (!await this.isAttachmentUploadedByUser(docSession, attId) && | ||
!await this.findAttachmentCellForUser(docSession, attId)) { | ||
if (!await this._checkAttachmentAccess(docSession, attId)) { | ||
throw new ErrorWithCode('ACL_DENY', 'Cannot access attachment', { | ||
status: 403, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you walk me through what this fixes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It applied ACL related accessses instead of connected user's.