Skip to content
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

Sharing key increase complexity #912

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/backend/middlewares/SharingMWs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ export class SharingMWs {
);
}

let sharingKey = SharingMWs.generateKey();
let sharingKey = SharingMWs.generateKey(Config.Sharing.sharingKeyLength);

// create one not yet used
// eslint-disable-next-line no-constant-condition
while (true) {
try {
await ObjectManagers.getInstance().SharingManager.findOne(sharingKey);
sharingKey = this.generateKey();
sharingKey = this.generateKey(Config.Sharing.sharingKeyLength);
} catch (err) {
break;
}
Expand Down Expand Up @@ -279,13 +279,14 @@ export class SharingMWs {
}
}

private static generateKey(): string {
function s4(): string {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
private static generateKey(length:number): string {
function randomInt(max:number): number {
return Math.floor(Math.random() * max);
}

return s4() + s4();
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
return [...Array(length).keys()].reduce(
(result) => result + characters.charAt(randomInt(characters.length)),
""
);
}
}
10 changes: 10 additions & 0 deletions src/common/config/public/ClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ export class ClientSharingConfig {
description: $localize`Requires password protected sharing links.`,
})
passwordRequired: boolean = false;
@ConfigProperty({
type: 'unsignedInt', min: 8, max: 64,
tags:
{
name: $localize`Sharing key length`,
priority: ConfigPriority.underTheHood
},
description: $localize`The longer the keys are, the harder they are to guess. Changing this number won't invalidate existing sharing.`,
})
sharingKeyLength: number = 32;
}

@SubConfigClass({tags: {client: true}, softReadonly: true})
Expand Down
13 changes: 13 additions & 0 deletions src/frontend/app/ui/gallery/share/share.gallery.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ a.list-shares-button {
a.list-shares-button:hover {
text-decoration: underline;
}

.ellipsisContainer {
position: relative;
}

.ellipsisText {
position: absolute;
left: 0;
right: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h5 class="modal-title" i18n>Share</h5>
</thead>
<tbody>
<tr *ngFor="let share of activeShares">
<td><a [href]="sharingService.getUrl(share)">{{share.sharingKey}}</a></td>
<td class="ellipsisContainer"><a [href]="sharingService.getUrl(share)" class="ellipsisText">{{share.sharingKey}}</a></td>
<td *ngIf="IsAdmin">{{share.creator.name}}</td>
<td>{{share.expires | date}}</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.ellipsisContainer {
position: relative;
}

.ellipsisText {
position: absolute;
left: 0;
right: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h5 i18n>Active shares</h5>
</thead>
<tbody>
<tr *ngFor="let share of shares">
<td><a [href]="sharingService.getUrl(share)">{{share.sharingKey}}</a></td>
<td class="ellipsisContainer"><a [href]="sharingService.getUrl(share)" class="ellipsisText">{{share.sharingKey}}</a></td>
<td>{{share.path}}</td>
<td>{{share.creator.name}}</td>
<td>{{share.expires | date}}</td>
Expand Down
Loading