mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
Merge commit from fork
* fix(share): only return share-visible field values on public share links The public share children and file detail endpoints returned every custom field value on an asset, while the share's field settings only hid them in the share UI. Filter fieldValues server-side to the fields turned on for the share, matching what GET /shares/:shareId/fields already returns. * fix(share): stop returning share passwords and compare them in constant time Share link responses included the saved password in plain text. Remove it from ShareLinkInfo; clients already get hasPassword. Check the password a guest enters with a constant-time comparison of SHA-256 digests instead of a string comparison. The share settings panel no longer pre-fills the saved password. When a password is set, the field starts empty with a hint, Save stays disabled until a new password is typed, and the field clears after saving. Turning the password off still removes it. * fix(kanban): limit task lists and task reads to the caller's projects Kanban checked only team membership for task reads, so a member invited to one project could list every task in the team and open any task, its linked files, comments and activity. - Task lists and the tasks linked to a file now include, for project-scoped members, only tasks in projects they belong to plus tasks they created, report, or are assigned to. Team-scoped members see every task as before. - Reading a task, its files, comments and activity follows the same rule: a project-scoped member outside the task's project needs to be its creator, reporter or assignee. - Linking a file to a task (create, update, or the link endpoints) now requires Read on that file, since linked files are shown to everyone who can read the task. * fix(security): sign only issued comment attachments and keep files on comment delete Kanban comment attachments: - Upload keys now include the team and the uploader: kanban/attachments/<teamId>/<userId>/<ulid>/<file name>. - addComment rejects any attachment key that was not issued to the comment author for the task's team, so a client can no longer store an arbitrary storage key in a comment. - When comments are read, only keys of kanban comment attachments for the task's team (or the previous kanban/attachments/<ulid>/<name> form) are presigned. Keys stored earlier that point anywhere else are dropped. Asset comment attachments: - createComment only links attachment uploads made by the commenter in the same project that are not linked to another comment. Project files can no longer be linked as comment attachments. - deleteComment deletes the stored object and asset only for attachment uploads not linked elsewhere; anything else linked to the comment is only unlinked. Upload keys: - Sanitize the file name in kanban and project attachment upload keys, as regular uploads already do, so a name cannot add path segments. - The local storage backend rejects keys with a '..' segment instead of resolving them into another object's path. * fix(security): enforce visibility and protect comment attachments --------- Co-authored-by: phj1081 <5908832+phj1081@users.noreply.github.com>
This commit is contained in:
@@ -438,6 +438,119 @@ describe('Share API', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('public share field values', () => {
|
||||
const shareLinkWithFields = {
|
||||
id: 'share1',
|
||||
name: 'My Share',
|
||||
isDisabled: false,
|
||||
allowDownload: false,
|
||||
rootFolderId: 'folder1',
|
||||
projectId: 'project1',
|
||||
password: null,
|
||||
expireAt: null,
|
||||
watermarkConfigId: null,
|
||||
fieldVisibility: { status: true, internalNote: false },
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any
|
||||
|
||||
const assetWithFields = {
|
||||
id: 'file1',
|
||||
name: 'a.png',
|
||||
sizeByte: 1,
|
||||
fileCount: 0,
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
proxyType: 'pdf',
|
||||
fieldValues: [
|
||||
{ fieldId: 'status', value: 'Approved' },
|
||||
{ fieldId: 'internalNote', value: 'not for guests' },
|
||||
{ fieldId: 'rating', value: 3 },
|
||||
],
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any
|
||||
|
||||
test('children only include field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithFields)
|
||||
vi.spyOn(assetService, 'listChildren').mockResolvedValue({
|
||||
data: [assetWithFields],
|
||||
pageInfo: { total: 1, cursor: undefined },
|
||||
})
|
||||
|
||||
const res = await app.request('/shares/share1/folders/folder1/children?assetType=file')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.data[0].fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
|
||||
test('children with watermark only include field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
|
||||
...shareLinkWithFields,
|
||||
watermarkConfigId: 'cfg1',
|
||||
})
|
||||
vi.spyOn(assetService, 'listChildren').mockResolvedValue({
|
||||
data: [assetWithFields],
|
||||
pageInfo: { total: 1, cursor: undefined },
|
||||
})
|
||||
vi.spyOn(assetService, 'resolveLatestVersionId').mockImplementation(async (id) => id)
|
||||
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
|
||||
|
||||
const res = await app.request('/shares/share1/folders/folder1/children?assetType=file')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.data[0].fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
|
||||
test('children include no field values when the share shows no fields', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
|
||||
...shareLinkWithFields,
|
||||
fieldVisibility: null,
|
||||
})
|
||||
vi.spyOn(assetService, 'listChildren').mockResolvedValue({
|
||||
data: [assetWithFields],
|
||||
pageInfo: { total: 1, cursor: undefined },
|
||||
})
|
||||
|
||||
const res = await app.request('/shares/share1/folders/folder1/children?assetType=file')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.data[0].fieldValues).toEqual([])
|
||||
})
|
||||
|
||||
test('file detail only includes field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithFields)
|
||||
vi.spyOn(assetService, 'getAsset').mockResolvedValue(assetWithFields)
|
||||
|
||||
const res = await app.request('/shares/share1/files/file1')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
|
||||
test('file detail with watermark only includes field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
|
||||
...shareLinkWithFields,
|
||||
watermarkConfigId: 'cfg1',
|
||||
})
|
||||
vi.spyOn(assetService, 'getAsset').mockResolvedValue({
|
||||
...assetWithFields,
|
||||
proxyType: 'image',
|
||||
media: { proxyType: 'image', videoTranscodes: [], imageTranscodes: [] },
|
||||
})
|
||||
vi.spyOn(assetService, 'resolveLatestVersionId').mockResolvedValue('file1')
|
||||
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
|
||||
|
||||
const res = await app.request('/shares/share1/files/file1')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /shares/:shareId/files/:fileId', () => {
|
||||
const shareLinkWithWatermark = {
|
||||
id: 'share1',
|
||||
|
||||
Reference in New Issue
Block a user