Skip to content

Commit ec4ca9a

Browse files
committed
Less permissive writes
1 parent 60e8b63 commit ec4ca9a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/commonhandler.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ export class CommonConnection {
340340
options
341341
)
342342
)
343+
if (cmd.dir === 'out' && cmd.id !== args.socketid) {
344+
// if we are sending out, it must be the clients own id!
345+
throw new Error('Sending data with foreign id is not permitted')
346+
}
343347
if (cmd.dir === 'in') {
344348
// this is the clients perspective, so what is coming in
345349
// for 'out' we have all we need
@@ -632,7 +636,14 @@ export class CommonConnection {
632636
token.accessRead = [
633637
(await realmhash).replace(/[+/]/g, '\\$&') + ':[a-zA-Z0-9-/+=]+'
634638
]
635-
if (args.canWrite) token.accessWrite = token.accessRead
639+
if (args.canWrite) {
640+
// you can only write to your own! Readinf everything is fine
641+
token.accessWrite = [
642+
(await realmhash).replace(/[+/]/g, '\\$&') +
643+
':' +
644+
(await clienthash).replace(/[+/]/g, '\\$&')
645+
]
646+
}
636647
if (setprimary) {
637648
if (!update.$addToSet) update.$addToSet = {}
638649
update.$addToSet.primaryRealms = args.lectureuuid

src/noteshandler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ export class NotesConnection extends CommonConnection {
392392
let token = {}
393393
// todo hash table
394394
token.accessWrite = [
395-
(await realmhash).replace(/[+/]/g, '\\$&') + ':[a-zA-Z0-9-/+=]+'
395+
(await realmhash).replace(/[+/]/g, '\\$&') +
396+
':' +
397+
(await clienthash).replace(/[+/]/g, '\\$&')
396398
]
397399
token.realm = await realmhash
398400
token.client = await clienthash

0 commit comments

Comments
 (0)