Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 8a142d7

Browse files
committed
fix(server): make division restriction null-safe
ACL checks previously assumed the user always had a division, and thus certain checks crash when given an undefined email. Fix the types and add guards in the checks where necessary.
1 parent a9694fc commit 8a142d7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

server/util/restrict.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import config, { ServerConfig } from '../config/server'
22

3-
type ACLCheck = (email: string) => boolean
3+
type ACLCheck = (email: string | undefined) => boolean
44

55
export interface ACL {
66
match: string;
@@ -16,11 +16,11 @@ interface CompiledACL {
1616
let acls: CompiledACL[]
1717

1818
const restrictionChecks: { [checkType: string]: (value: string) => ACLCheck } = {
19-
domain: value => email => email.endsWith('@' + value),
19+
domain: value => email => email?.endsWith('@' + value) ?? false,
2020
email: value => email => email === value,
2121
regex: value => {
2222
const re = new RegExp(value)
23-
return email => re.test(email)
23+
return email => email === undefined ? false : re.test(email)
2424
},
2525
any: value => email => true // eslint-disable-line @typescript-eslint/no-unused-vars
2626
}
@@ -45,7 +45,7 @@ export const compileACLs = (): void => {
4545

4646
compileACLs()
4747

48-
export const allowedDivisions = (email: string): string[] => {
48+
export const allowedDivisions = (email: string | undefined): string[] => {
4949
for (const acl of acls) {
5050
if (acl.check(email)) {
5151
return acl.divisions
@@ -54,6 +54,6 @@ export const allowedDivisions = (email: string): string[] => {
5454
return []
5555
}
5656

57-
export const divisionAllowed = (email: string, division: string): boolean => {
57+
export const divisionAllowed = (email: string | undefined, division: string): boolean => {
5858
return allowedDivisions(email).includes(division)
5959
}

0 commit comments

Comments
 (0)