Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:shares): enforce share-outside permission on space shares

johaven308482b6d48e
diff --git a/backend/src/applications/shares/services/shares-manager.service.spec.ts b/backend/src/applications/shares/services/shares-manager.service.spec.ts
index c2c15b93..fdcfe57e 100644
--- a/backend/src/applications/shares/services/shares-manager.service.spec.ts
+++ b/backend/src/applications/shares/services/shares-manager.service.spec.ts
@@ -7,6 +7,7 @@ import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
import { LINK_TYPE } from '../../links/constants/links'
import { LinksQueries } from '../../links/services/links-queries.service'
import { NotificationsManager } from '../../notifications/services/notifications-manager.service'
+import { SPACE_OPERATION } from '../../spaces/constants/spaces'
import { SpacesQueries } from '../../spaces/services/spaces-queries.service'
import * as permissionsUtils from '../../spaces/utils/permissions'
import { GUEST_PERMISSION } from '../../users/constants/user'
@@ -170,6 +171,34 @@ describe(SharesManager.name, () => {
})
})
+ describe('createShare', () => {
+ it('forbids creating a share from a space without the share outside permission', async () => {
+ sharesQueriesMock.uniqueShareAlias.mockResolvedValueOnce('shared-file')
+ spacesQueriesMock.permissions.mockResolvedValueOnce({ id: 7, alias: 'space-1' })
+ vi.mocked(permissionsUtils.havePermission).mockReturnValueOnce(false)
+
+ const createShareDto: any = {
+ name: 'Shared file',
+ enabled: true,
+ externalPath: null,
+ file: {
+ id: 42,
+ ownerId: null,
+ path: 'root/file.txt',
+ space: { alias: 'space-1', root: { alias: 'root' } }
+ },
+ members: [],
+ links: []
+ }
+
+ await expect(service.createShare(user, createShareDto)).rejects.toEqual(
+ new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)
+ )
+ expect(permissionsUtils.havePermission).toHaveBeenCalledWith('ENV_PERMS', SPACE_OPERATION.SHARE_OUTSIDE)
+ expect(sharesQueriesMock.createShare).not.toHaveBeenCalled()
+ })
+ })
+
describe('getShareWithMembers', () => {
it('returns the share and calls setAllowedPermissions', async () => {
const share: any = { id: 10, file: {} }
diff --git a/backend/src/applications/shares/services/shares-manager.service.ts b/backend/src/applications/shares/services/shares-manager.service.ts
index bbd84102..a3d022b9 100644
--- a/backend/src/applications/shares/services/shares-manager.service.ts
+++ b/backend/src/applications/shares/services/shares-manager.service.ts
@@ -181,6 +181,13 @@ export class SharesManager {
// compute space permissions
const space: SpaceEnv = new SpaceEnv(spacePermissions)
space.setPermissions(true)
+ if (!havePermission(space.envPermissions, SPACE_OPERATION.SHARE_OUTSIDE)) {
+ this.logger.warn({
+ tag: this.createShare.name,
+ msg: `is not allowed to share outside of : *${space.alias}* (${space.id})`
+ })
+ throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)
+ }
// intersect space permissions for members
for (const m of createOrUpdateShareDto.members) {
m.permissions = intersectPermissions(space.envPermissions, m.permissions)