Skip to content

Commit 339244e

Browse files
committed
Matrix is being spammed with email users
We already allowed email registrations to Matrix, so we can't disable this connection, since that would break logging in for existing users. That leaves us with only one option: deny at pre-user-registration. Jira: IAM-1617
1 parent e936904 commit 339244e

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "auth0_trigger_actions" "pre_user_registration_flow" {
2+
trigger = "pre-user-registration"
3+
actions {
4+
id = auth0_action.deny_registration.id
5+
display_name = auth0_action.deny_registration.name
6+
}
7+
}
8+
9+
resource "auth0_action" "deny_registration" {
10+
name = "denyRegistration"
11+
runtime = "node22"
12+
deploy = true
13+
code = file("${path.module}/actions/denyRegistration.js")
14+
supported_triggers {
15+
id = "pre-user-registration"
16+
version = "v2"
17+
}
18+
}

tf/actions/denyRegistration.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Reject users from registering for an application (by client id) using a
2+
// specific connection.
3+
//
4+
// This is a workaround for disabling a connection entirely for an application,
5+
// since we may have allowed registrations already.
6+
//
7+
// If we instead disabled the connection then we'd break logins for users who
8+
// only have that connection available.
9+
//
10+
// DEBT(bhee): LDAP's connection name is
11+
// * `Mozilla-LDAP` on prod;
12+
// * `Mozilla-LDAP-Dev` on dev.
13+
//
14+
// If we need to deny registrations on those, for some reason, we'll need to
15+
// think of a better way. Connection Ids are not stable across tenants either.
16+
17+
exports.onExecutePreUserRegistration = async (event, api) => {
18+
const CLIENT_CONNECTIONS_DENYLIST = {
19+
// Matrix, IAM-1617
20+
pFf6sBIfp4n3Wcs3F9Q7a9ry8MTrbi2F: ["email"],
21+
};
22+
23+
const denylist = CLIENT_CONNECTIONS_DENYLIST[event.client.client_id] ?? [];
24+
25+
if (denylist.includes(event.connection.name)) {
26+
return api.access.deny(
27+
`Not allowed to register for ${event.client.name} using ${event.connection.name}.`
28+
);
29+
}
30+
31+
return;
32+
};

tf/tests/denyRegistration.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const _ = require("lodash");
2+
const eventObj = require("./modules/event.json");
3+
const {
4+
onExecutePreUserRegistration,
5+
} = require("../actions/denyRegistration.js");
6+
7+
beforeEach(() => {
8+
_event = _.cloneDeep(eventObj);
9+
api = {
10+
access: {
11+
deny: jest.fn(),
12+
},
13+
};
14+
});
15+
16+
test("Should not deny registration an app we haven't specified", async () => {
17+
await onExecutePreUserRegistration(_event, api);
18+
expect(api.access.deny).not.toHaveBeenCalled();
19+
});
20+
21+
test("Should deny registration for Matrix", async () => {
22+
_event.connection.name = "email";
23+
_event.client.client_id = "pFf6sBIfp4n3Wcs3F9Q7a9ry8MTrbi2F";
24+
await onExecutePreUserRegistration(_event, api);
25+
expect(api.access.deny).toHaveBeenCalled();
26+
});

0 commit comments

Comments
 (0)