Skip to content

Commit 3f5bea0

Browse files
committed
restrict exchange and replyto
1 parent 8084842 commit 3f5bea0

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

OpenFlow/src/Messages/Message.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ export class Message {
744744
}
745745
if (!NoderedUtil.IsNullEmpty(msg.queuename) && msg.queuename.toLowerCase() == "openflow") {
746746
throw new Error("Access denied");
747+
} else if (!NoderedUtil.IsNullEmpty(msg.exchange) && msg.exchange.toLowerCase() == "openflow") {
748+
throw new Error("Access denied");
749+
} else if (!NoderedUtil.IsNullEmpty(msg.replyto) && msg.replyto.toLowerCase() == "openflow") {
750+
throw new Error("Access denied");
747751
} else if (NoderedUtil.IsNullEmpty(msg.queuename) && NoderedUtil.IsNullEmpty(msg.exchange)) {
748752
throw new Error("queuename or exchange must be given");
749753
}
@@ -806,6 +810,41 @@ export class Message {
806810
}
807811
}
808812
}
813+
if ((Config.amqp_force_sender_has_read || Config.amqp_force_sender_has_invoke) && !NoderedUtil.IsNullEmpty(msg.exchange)) {
814+
const tuser = Crypt.verityToken(jwt);
815+
let allowed: boolean = false;
816+
if (tuser._id == msg.exchange) {
817+
// Queue is for me
818+
allowed = true;
819+
} else if (tuser.roles != null) {
820+
// Queue is for a role i am a member of.
821+
const isrole = tuser.roles.filter(x => x._id == msg.exchange);
822+
if (isrole.length > 0) allowed = true;
823+
}
824+
if (!allowed) {
825+
let mq = Auth.getUser(msg.exchange, "mqe");
826+
if (mq == null) {
827+
const arr = await Config.db.query({ "name": msg.exchange, "_type": "exchange" }, { name: 1, _acl: 1 }, 1, 0, null, "mq", rootjwt, undefined, undefined, span);
828+
if (arr.length > 0) {
829+
await Auth.AddUser(arr[0] as any, msg.exchange, "mqe");
830+
mq = arr[0] as any;
831+
}
832+
}
833+
if (mq != null) {
834+
if (Config.amqp_force_sender_has_invoke) {
835+
if (!DatabaseConnection.hasAuthorization(tuser, mq, Rights.invoke)) {
836+
throw new Error("Unknown exchange or access denied, missing invoke permission on exchange object " + tuser.name);
837+
}
838+
} else {
839+
if (!DatabaseConnection.hasAuthorization(tuser, mq, Rights.read)) {
840+
throw new Error("Unknown exchange or access denied, missing read permission on exchange object " + tuser.name);
841+
}
842+
843+
}
844+
allowed = true;
845+
}
846+
}
847+
}
809848
const sendthis: any = msg.data;
810849
if (NoderedUtil.IsNullEmpty(msg.jwt) && !NoderedUtil.IsNullEmpty(msg.data.jwt)) {
811850
msg.jwt = msg.data.jwt;

0 commit comments

Comments
 (0)