CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/db-schema/name-rules.ts
Views: 687
1
/* Checks that name satisfies the following constraints
2
Inspired by -- https://github.com/isiahmeadows/github-limits
3
4
Each function checks the basic rules, but NOT for uniqueness,
5
which requires a DB query.
6
7
If a rule fails, throws an Error.
8
9
The URL schema is
10
11
https://cocalc.com/[account name]/[project name]/[shared path name]
12
13
We are only using these URL's for the share server.
14
We only use such a URL if all segments are specified.
15
16
NOTE: at some point we considered using these url's for more than just
17
the share server, and maybe when some segments aren't specified. If we
18
did that, we have to have a lot more constraints on the segments, e.g.,
19
we can't allow "files" for the shared path name. But we are NOT doing
20
that.
21
*/
22
23
import { is_valid_uuid_string } from "../misc";
24
25
export function isReserved(name: string): boolean {
26
return RESERVED.has(name.toLowerCase());
27
}
28
29
/*
30
Account name:
31
- between 1 and 39 characters
32
- doesn't start with a -
33
- only includes the characters 0-9,a-z,A-Z,-
34
- Don't allow uuid's.
35
- cannot include consecutive hyphens
36
*/
37
export function checkAccountName(name: string) {
38
if (name.length < 1) {
39
throw Error("name must have at least 1 character");
40
}
41
if (name.length > 39) {
42
throw Error("name must have at most 39 characters");
43
}
44
if (is_valid_uuid_string(name)) {
45
throw Error("name must not be a v4 UUID");
46
}
47
if (name.includes("--")) {
48
throw Error("name must not contain consecutive hyphens");
49
}
50
if (!/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i.test(name)) {
51
throw Error(
52
"name must contain only a-z,A-Z,0-9, or -, and not start with hyphen.",
53
);
54
}
55
// Check for reserved names.
56
if (isReserved(name)) {
57
throw Error(`username "${name}" is reserved -- not available`);
58
}
59
}
60
61
/*
62
Project name:
63
64
- Max length: 100 characters
65
- All characters must be either a hyphen (-), a period (.), or alphanumeric
66
- Unique amongst projects with given owner (that's a separate db query)
67
*/
68
export function checkProjectName(name: string) {
69
if (name.length < 1) {
70
throw Error("name must have at least 1 character");
71
}
72
if (name.length > 100) {
73
throw Error("name must have at most 100 characters");
74
}
75
if (!/^[\.a-z\d](?:[\.a-z\d]|-(?=[\.a-z\d])){0,99}$/i.test(name)) {
76
throw Error(
77
"name must contain only a-z,A-Z,0-9, . or -, and not start with hyphen or have spaces.",
78
);
79
}
80
}
81
82
/*
83
Public path name:
84
85
- Max length: 100 characters
86
- All characters must be either a hyphen (-), a period (.), or alphanumeric
87
- Unique amongst public paths in a given project (a separate db query)
88
*/
89
90
export function checkPublicPathName(name: string) {
91
if (name.length < 1) {
92
throw Error("name must have at least 1 character");
93
}
94
if (name.length > 100) {
95
throw Error("name must have at most 100 characters");
96
}
97
if (!/^[\.a-z\d](?:[\.a-z\d]|-(?=[\.a-z\d])){0,99}$/i.test(name)) {
98
throw Error(
99
"name must contain only a-z,A-Z,0-9, . or -, and not start with hyphen or have spaces.",
100
);
101
}
102
}
103
104
// Combined words from what we use, https://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
105
// and https://github.com/Mottie/github-reserved-names/blob/master/reserved-names.json and
106
// https://github.com/Mottie/github-reserved-names and random other things.
107
// If you add more and want to clean this up in the console, this may be helpful:
108
// Array.from(RESERVED).sort().join(' ')
109
const RESERVED = new Set(
110
`\
111
0
112
400
113
401
114
402
115
403
116
404
117
405
118
406
119
407
120
408
121
409
122
410
123
411
124
412
125
413
126
414
127
415
128
416
129
417
130
418
131
419
132
420
133
421
134
422
135
423
136
424
137
425
138
426
139
427
140
428
141
429
142
430
143
431
144
500
145
501
146
502
147
503
148
504
149
505
150
506
151
507
152
508
153
509
154
510
155
511
156
about
157
access
158
account
159
accounts
160
action
161
actions
162
activate
163
activities
164
activity
165
ad
166
add
167
address
168
adm
169
admin
170
administration
171
administrator
172
ads
173
adult
174
advertising
175
advisories
176
affiliate
177
affiliates
178
ajax
179
alive
180
all
181
alpha
182
analysis
183
analytics
184
android
185
anon
186
anonymous
187
any
188
api
189
app
190
apps
191
archive
192
archives
193
article
194
articles
195
asct
196
ask
197
asset
198
assets
199
atom
200
attributes
201
auth
202
authentication
203
avatar
204
backup
205
balancer-manager
206
banner
207
banners
208
beta
209
better
210
billing
211
bin
212
blob
213
blobs
214
blog
215
blogs
216
board
217
book
218
bookmark
219
bot
220
bots
221
bounty
222
branches
223
bug
224
business
225
businesses
226
c
227
cache
228
cadastro
229
calendar
230
call
231
campaign
232
cancel
233
captcha
234
career
235
careers
236
cart
237
case-studies
238
categories
239
category
240
cdn
241
central
242
certification
243
cgi
244
cgi-bin
245
changelog
246
chat
247
check
248
checking
249
checkout
250
cla
251
client
252
cliente
253
clients
254
cloud
255
cocalc
256
cocksucker
257
code
258
codereview
259
collection
260
collections
261
comercial
262
comment
263
comments
264
commit
265
commits
266
communities
267
community
268
companies
269
company
270
compare
271
compras
272
compute
273
config
274
configuration
275
connect
276
contact
277
contact_us
278
contact-us
279
contactus
280
contest
281
contribute
282
contributing
283
cookbook
284
cookies
285
corp
286
coupon
287
coupons
288
create
289
crm
290
css
291
cunt
292
customer
293
customer-stories
294
customers
295
customize
296
dashboard
297
dashboards
298
data
299
db
300
default
301
delete
302
demo
303
design
304
designer
305
destroy
306
dev
307
devel
308
develop
309
developer
310
developers
311
diagram
312
diary
313
dict
314
dictionary
315
die
316
diff
317
dir
318
direct_messages
319
directory
320
discover
321
discussions
322
dist
323
doc
324
docs
325
documentation
326
domain
327
download
328
downloads
329
downtime
330
ecommerce
331
edit
332
editor
333
editors
334
edu
335
education
336
email
337
embed
338
employment
339
empty
340
end
341
enterprise
342
entries
343
entry
344
error
345
errors
346
eval
347
event
348
events
349
exit
350
explore
351
facebook
352
faq
353
favorite
354
favorites
355
feature
356
featured
357
features
358
feed
359
feedback
360
feeds
361
file
362
files
363
first
364
fixtures
365
flash
366
fleet
367
fleets
368
flog
369
follow
370
followers
371
following
372
font
373
fonts
374
forgot
375
forked
376
form
377
forum
378
forums
379
founder
380
free
381
friend
382
friends
383
ftp
384
fuck
385
gadget
386
gadgets
387
game
388
games
389
garage
390
get
391
ghost
392
gift
393
gifts
394
gist
395
gists
396
github
397
github.com
398
gitlab
399
gitlab.com
400
grafana
401
graph
402
graphs
403
group
404
groups
405
guest
406
guests
407
guide
408
guides
409
help
410
help-wanted
411
home
412
homepage
413
hooks
414
host
415
hosting
416
hostmaster
417
hostname
418
hovercards
419
howto
420
hpg
421
html
422
http
423
httpd
424
https
425
hub
426
i
427
iamges
428
icon
429
icons
430
id
431
idea
432
ideas
433
identity
434
image
435
images
436
imap
437
img
438
inbox
439
include
440
includes
441
index
442
indice
443
individual
444
info
445
information
446
inquiry
447
instagram
448
integration
449
interfaces
450
intern
451
internal
452
intranet
453
introduction
454
invalid-email-address
455
investors
456
invitations
457
invite
458
invoice
459
ipad
460
iphone
461
irc
462
is
463
issue
464
issues
465
it
466
item
467
items
468
java
469
javascript
470
job
471
jobs
472
join
473
journal
474
journals
475
js
476
json
477
jump
478
knowledgebase
479
lab
480
labs
481
language
482
languages
483
last
484
launch
485
layouts
486
ldap-status
487
learn
488
legal
489
library
490
license
491
licenses
492
link
493
links
494
linux
495
list
496
listings
497
lists
498
log
499
log_in
500
log_out
501
log-in
502
log-out
503
login
504
logos
505
logout
506
logs
507
m
508
mac
509
mail
510
mail1
511
mail2
512
mail3
513
mail4
514
mail5
515
mailer
516
mailing
517
maintenance
518
malware
519
man
520
manager
521
manual
522
map
523
maps
524
marketing
525
marketplace
526
master
527
me
528
media
529
member
530
members
531
mention
532
mentioned
533
mentioning
534
mentions
535
message
536
messages
537
messenger
538
metrics
539
microblog
540
microblogs
541
migrating
542
milestones
543
mine
544
mirrors
545
mis
546
misc
547
mob
548
mobile
549
module
550
modules
551
monitor
552
motherfucker
553
movie
554
movies
555
mp3
556
msg
557
msn
558
music
559
musicas
560
mx
561
my
562
mysql
563
name
564
named
565
nan
566
navi
567
navigation
568
nbextensions
569
net
570
network
571
new
572
news
573
newsletter
574
nick
575
nickname
576
nocodb
577
node
578
nodes
579
none
580
nonprofit
581
nonprofits
582
notes
583
notices
584
noticias
585
notification
586
notifications
587
notify
588
ns
589
ns1
590
ns10
591
ns2
592
ns3
593
ns4
594
ns5
595
ns6
596
ns7
597
ns8
598
ns9
599
null
600
oauth
601
oauth_clients
602
offer
603
offers
604
office
605
official
606
old
607
online
608
open-source
609
openid
610
operator
611
order
612
orders
613
organisations
614
organization
615
organizations
616
orgs
617
overview
618
owner
619
owners
620
page
621
pager
622
pages
623
panel
624
partners
625
password
626
password-reset
627
payment
628
payments
629
perl
630
personal
631
phone
632
photo
633
photoalbum
634
photos
635
php
636
phpmyadmin
637
phppgadmin
638
phpredisadmin
639
pic
640
pics
641
ping
642
piss
643
plan
644
plans
645
plugin
646
plugins
647
policies
648
policy
649
poll
650
polls
651
pop
652
pop3
653
popular
654
popularity
655
portal
656
post
657
postfix
658
postmaster
659
posts
660
pr
661
premium
662
press
663
price
664
pricing
665
primus
666
privacy
667
privacy_policy
668
privacy-policy
669
privacypolicy
670
private
671
processes
672
product
673
products
674
professional
675
profile
676
profiles
677
project
678
projects
679
prometheus
680
promo
681
pub
682
public
683
pulls
684
purchase
685
purchases
686
purpose
687
put
688
python
689
query
690
random
691
ranking
692
raw
693
rdf
694
rdfs
695
read
696
readme
697
recent
698
recommendations
699
recruit
700
recruitment
701
redeem
702
register
703
registration
704
release
705
releases
706
remove
707
render
708
replies
709
reply
710
report
711
reports
712
repositories
713
repository
714
req
715
request
716
requests
717
reset
718
resources
719
restore
720
revert
721
roc
722
root
723
rss
724
ruby
725
rule
726
sag
727
sagemath
728
sagemathinc
729
sale
730
sales
731
sample
732
samples
733
save
734
save-net-neutrality
735
saved
736
school
737
scraping
738
script
739
scripts
740
search
741
secure
742
security
743
self
744
send
745
server
746
server-info
747
server-status
748
service
749
services
750
session
751
sessions
752
setting
753
settings
754
setup
755
share
756
shareholders
757
shit
758
shop
759
show
760
showcases
761
sign_in
762
sign_up
763
sign-in
764
sign-up
765
signin
766
signout
767
signup
768
site
769
sitemap
770
sites
771
smartphone
772
smtp
773
snapshots
774
software
775
soporte
776
source
777
spam
778
spec
779
special
780
sponsors
781
sql
782
src
783
ssh
784
ssl
785
ssladmin
786
ssladministrator
787
sslwebmaster
788
sso
789
staff
790
stage
791
staging
792
star
793
starred
794
stars
795
start
796
stat
797
state
798
static
799
statistics
800
stats
801
status
802
statuses
803
storage
804
store
805
stores
806
stories
807
style
808
styleguide
809
stylesheet
810
stylesheets
811
subdomain
812
subscribe
813
subscriptions
814
suggest
815
suggestion
816
suggestions
817
suporte
818
support
819
survey
820
surveys
821
suspended
822
svn
823
swf
824
sys
825
sysadmin
826
sysadministrator
827
system
828
tablet
829
tablets
830
tag
831
talk
832
talks
833
task
834
tasks
835
teach
836
teacher
837
teachers
838
teaching
839
team
840
teams
841
tech
842
telnet
843
template
844
templates
845
ten
846
term
847
terms
848
terms_of_service
849
terms-of-service
850
termsofservice
851
test
852
test1
853
test2
854
test3
855
teste
856
testimonials
857
testing
858
tests
859
theme
860
themes
861
thread
862
threads
863
timeline
864
timetravel
865
tits
866
tmp
867
todo
868
token
869
tool
870
tools
871
top
872
topic
873
topics
874
tos
875
tour
876
train
877
training
878
translations
879
tree
880
trending
881
trends
882
try
883
tutorial
884
tutorials
885
tux
886
tv
887
twitter
888
twittr
889
undef
890
unfollow
891
unsubscribe
892
update
893
updates
894
upload
895
uploads
896
url
897
usage
898
user
899
username
900
users
901
usuario
902
vendas
903
ver
904
version
905
video
906
videos
907
visitor
908
visualization
909
voucher
910
vouchers
911
w
912
watch
913
watching
914
weather
915
web
916
webapp
917
webhook
918
webhooks
919
webmail
920
webmaster
921
website
922
websites
923
welcome
924
widget
925
widgets
926
wiki
927
win
928
windows
929
word
930
work
931
works
932
works-with
933
workshop
934
ww
935
wws
936
www
937
www0
938
www1
939
www2
940
www3
941
www4
942
www5
943
www6
944
www7
945
www8
946
www9
947
wwws
948
wwww
949
xfn
950
xml
951
xmpp
952
xpg
953
xxx
954
yaml
955
year
956
yml
957
you
958
yourdomain
959
yourname
960
yoursite
961
yourusername`.split("\n"),
962
);
963
964
// for testing only
965
if (process.env["NODE_DEV"] === "TEST") {
966
exports.RESERVED = RESERVED;
967
}
968
969