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

Commit 596b8d9

Browse files
authored
Merge branch 'master' into refactor/stricter-typechecking
2 parents 3a1c72c + 163e25b commit 596b8d9

File tree

10 files changed

+76
-35
lines changed

10 files changed

+76
-35
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,5 @@ jobs:
115115
password: ${{ secrets.DOCKERHUB_PASS }}
116116
repository: redpwn/rctf
117117
# TODO: handle tagging releases correctly
118-
tags: ${{ github.sha }}
118+
tags: master,${{ github.sha }}
119119
# TODO: add cache_froms once we have full releases
120-
- name: Deploy installer
121-
uses: netlify/actions/build@master
122-
env:
123-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124-
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_INSTALL_SITE_ID }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ yarn-error.log*
1010
/conf.d/*
1111
!/conf.d/.keep
1212
/docs/site
13-
/install/build
1413

1514
# Upload provider dir
1615
/uploads

docker-compose.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '2.2'
22
services:
33
rctf:
4-
image: redpwn/rctf:${RCTF_GIT_COMMIT}
4+
image: redpwn/rctf:${RCTF_GIT_REF}
55
restart: always
66
ports:
77
- '127.0.0.1:8080:80'
@@ -11,11 +11,6 @@ services:
1111
- .env
1212
environment:
1313
- PORT=80
14-
- RCTF_DATABASE_HOST=postgres
15-
- RCTF_DATABASE_DATABASE=rctf
16-
- RCTF_DATABASE_USERNAME=rctf
17-
- RCTF_REDIS_HOST=redis
18-
- RCTF_DATABASE_MIGRATE=before
1914
volumes:
2015
- ./conf.d:/app/conf.d
2116
depends_on:

install/_redirects

Lines changed: 0 additions & 1 deletion
This file was deleted.

install/build.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

install/install.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ do_install() {
6767

6868
info "Configuring rCTF..."
6969

70-
RCTF_GIT_COMMIT="${RCTF_GIT_COMMIT:-"{{git_commit}}"}"
70+
RCTF_GIT_REF="${RCTF_GIT_REF:-"master"}"
7171

7272
mkdir -p conf.d data/rctf-postgres data/rctf-redis
7373

7474
printf "%s\n" \
7575
"RCTF_DATABASE_PASSWORD=$(get_key)" \
7676
"RCTF_REDIS_PASSWORD=$(get_key)" \
77-
"RCTF_GIT_COMMIT=$RCTF_GIT_COMMIT" \
77+
"RCTF_GIT_REF=$RCTF_GIT_REF" \
7878
> .env
7979

8080
printf "%s\n" \
@@ -94,9 +94,20 @@ do_install() {
9494
"endTime: $(date -d +1week +%s)000" \
9595
> conf.d/02-ctf.yaml
9696

97+
printf "%s\n" \
98+
"database:" \
99+
" sql:" \
100+
" host: postgres" \
101+
" user: rctf" \
102+
" database: rctf" \
103+
" redis:" \
104+
" host: redis" \
105+
" migrate: before" \
106+
> conf.d/03-db.yaml
107+
97108
info "Downloading rCTF..."
98109

99-
curl -fsSO "https://raw.githubusercontent.com/redpwn/rctf/$RCTF_GIT_COMMIT/docker-compose.yml"
110+
curl -fsSO "https://raw.githubusercontent.com/redpwn/rctf/$RCTF_GIT_REF/docker-compose.yml"
100111
docker-compose pull
101112

102113
info "Finished installation to ${RCTF_INSTALL_PATH}."

server/auth/token.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,43 @@ export enum tokenKinds {
1414
ctftimeAuth = 4
1515
}
1616

17-
export enum VerifyTokenKinds {
18-
update = 'update',
19-
register = 'register'
20-
}
17+
export type VerifyTokenKinds = 'update' | 'register' | 'recover'
2118

2219
export type AuthTokenData = string
20+
2321
export type TeamTokenData = string
24-
export interface VerifyTokenData {
22+
23+
interface BaseVerifyTokenData {
2524
verifyId: string
2625
kind: VerifyTokenKinds
26+
}
27+
28+
export interface RegisterVerifyTokenData extends BaseVerifyTokenData {
29+
kind: 'register'
30+
email: User['email']
31+
name: User['name']
32+
division: User['division']
33+
}
34+
35+
export interface UpdateVerifyTokenData extends BaseVerifyTokenData {
36+
kind: 'update'
2737
userId: User['id']
2838
email: User['email']
2939
division: User['division']
3040
}
31-
export type CtftimeAuthTokenData = string
41+
42+
export interface RecoverTokenData extends BaseVerifyTokenData {
43+
kind: 'recover'
44+
userId: User['id']
45+
email: User['email']
46+
}
47+
48+
export type VerifyTokenData = RegisterVerifyTokenData | UpdateVerifyTokenData | RecoverTokenData
49+
50+
export interface CtftimeAuthTokenData {
51+
name: User['name']
52+
ctftimeId: User['ctftimeId']
53+
}
3254

3355
// Internal map of type definitions for typing purposes only -
3456
// this type does not describe a real data-structure

server/database/users.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { ExtractQueryType } from './util'
77
export interface User {
88
id: string;
99
name: string;
10-
email: string;
10+
email?: string;
1111
division: keyof ServerConfig['divisions'];
12-
ctftimeId: string;
12+
ctftimeId?: string;
1313
perms: number;
1414
}
1515

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
}

test/unit/restrict.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,28 @@ test.serial('throws error on invalid matcher', t => {
8585
error = t.throws(restrict.compileACLs)
8686
t.is(error.message, 'Unrecognized ACL matcher "__proto__"')
8787
})
88+
89+
test.serial('denies no email with all matchers except any', t => {
90+
config.divisionACLs = [{
91+
match: 'domain',
92+
value: 'good-domain.com',
93+
divisions: ['domain']
94+
}, {
95+
match: 'email',
96+
97+
divisions: ['email']
98+
}, {
99+
match: 'regex',
100+
value: '^regex-email(-[a-z]+)[email protected]$',
101+
divisions: ['regex']
102+
}, {
103+
match: 'any',
104+
value: '',
105+
divisions: ['any']
106+
}]
107+
restrict.compileACLs()
108+
t.false(restrict.divisionAllowed(undefined, 'domain'))
109+
t.false(restrict.divisionAllowed(undefined, 'email'))
110+
t.false(restrict.divisionAllowed(undefined, 'regex'))
111+
t.true(restrict.divisionAllowed(undefined, 'any'))
112+
})

0 commit comments

Comments
 (0)