Skip to content

Commit bc87db6

Browse files
authored
Merge pull request #504 from bheesham/deny-email-registration-for-matrix
Deny email registration for Matrix
2 parents 0ca62a9 + 339244e commit bc87db6

5 files changed

Lines changed: 113 additions & 31 deletions

File tree

tf/.terraform.lock.hcl

Lines changed: 36 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
auth0 = {
44
source = "auth0/auth0"
5-
version = "1.2.0"
5+
version = "1.15.0"
66
}
77
}
88
backend "gcs" {

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)