Skip to content

Commit ecde440

Browse files
committed
refactor(nginx): update user authentication checks to use empty string for undefined tokens
1 parent eda6324 commit ecde440

5 files changed

+20
-9
lines changed

packages/nginx/etc/nginx/templates/location.d/55-region-public.conf.template

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# Nitrobase file location that can be accessed by anyone.
33

44
location /$nitrobaseRegionPublic/ {
5-
if ($authUserToken = 0) {
6-
return 403; # User not defined
5+
if ($authUserToken = "") {
6+
# User not defined
7+
return 403;
78
break;
89
}
910

packages/nginx/etc/nginx/templates/location.d/56-region-authenticated.conf.template

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
# Nitrobase file location that can be accessed by authenticated users.
33

44
location /$nitrobaseRegionAuthenticated/ {
5-
if ($authUserToken = 0) {
6-
return 403; # User not defined
5+
if ($authUserToken = "") {
6+
# User not defined
7+
return 403;
78
break;
89
}
910

1011
if (!-f $document_root/$userLocation/.token/$authUserToken.asn) {
12+
# Token file not found then user not authenticated
1113
return 403;
1214
break;
1315
}

packages/nginx/etc/nginx/templates/location.d/57-region-managers.conf.template

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
# Nitrobase file location that can be accessed by admin and managers only.
33

44
location /$nitrobaseRegionManagers/ {
5-
if ($authUserToken = 0) {
6-
return 403; # User not defined
5+
if ($authUserToken = "") {
6+
# User not defined
7+
return 403;
78
break;
89
}
910

1011
if (!-f $document_root/$userLocation/.token/$authUserToken.asn) {
12+
# Token file not found then user not authenticated
1113
return 403;
1214
break;
1315
}
1416

1517
if (!-f $document_root/$userLocation/.auth/manager.asn) {
18+
# Manager authentication file not found then user not a manager
1619
return 403;
1720
break;
1821
}

packages/nginx/etc/nginx/templates/location.d/58-region-per-user.conf.template

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@
33

44
location ~ ^/(?<requestLocation>$nitrobaseRegionPerUser/[A-z0-9_=-]+/[A-z0-9_=-]+)/ {
55

6-
if ($authUserToken = 0) {
7-
return 403; # User not defined
6+
if ($authUserToken = "") {
7+
# User not defined
8+
return 403;
89
break;
910
}
1011

1112
if (!-f $document_root/$userLocation/.token/$authUserToken.asn) {
13+
# Token file not found then user not authenticated
1214
return 403;
1315
break;
1416
}
1517

1618
try_files $uri =404;
1719

1820
if (-f $document_root/$userLocation/.auth/manager.asn) {
21+
# Manager authentication file found then user is a manager and can access other user's files
1922
break;
2023
}
2124

2225
if ($userLocation = $requestLocation) {
26+
# User requested his own files
2327
break;
2428
}
2529

30+
# User requested other user's files and is not a manager
2631
return 403;
2732
}

packages/nginx/etc/nginx/templates/location.d/59-region-per-owner.conf.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Nitrobase file location specific to each owner id.
33

44
location ~ ^/$nitrobaseRegionPerOwner/[A-z0-9_=-]+/[A-z0-9_=-]+/ {
5-
if ($authUserToken = 0) {
5+
if ($authUserToken = "") {
66
return 403; # User not defined
77
break;
88
}

0 commit comments

Comments
 (0)