Skip to content

Commit 63ff3af

Browse files
authored
fix: restrict share link route tokens to UUID length (Stirling-Tools#7626)
1 parent 4457260 commit 63ff3af

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

app/common/src/main/java/stirling/software/common/util/RequestUriUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
public class RequestUriUtils {
66

7-
private static final Pattern SHARE_LINK_PATTERN = Pattern.compile("^/share/[^/]+/?$");
7+
// Share tokens are 36-char lowercase UUIDs (UUID.randomUUID().toString()); match exactly
8+
private static final Pattern SHARE_LINK_PATTERN =
9+
Pattern.compile(
10+
"^/share/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/?$");
811
// Invite tokens are 36-char lowercase UUIDs (UUID.randomUUID().toString()); match exactly
912
private static final Pattern INVITE_LINK_PATTERN =
1013
Pattern.compile(
@@ -73,7 +76,7 @@ public static boolean isStaticResource(String contextPath, String requestURI) {
7376
// cookie, so the server can't authenticate the navigation itself). The
7477
// portal gates access via its own auth gate + RequirePortalAccess, and its
7578
// data APIs stay protected, so serving the shell pre-auth is safe.
76-
if (normalizedUri.equals("/processor") || normalizedUri.startsWith("/processor/")) {
79+
if ("/processor".equals(normalizedUri) || normalizedUri.startsWith("/processor/")) {
7780
return true;
7881
}
7982

app/common/src/test/java/stirling/software/common/util/RequestUriUtilsTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,24 @@ void testIsPublicAuthEndpoint_shareLinkToken() {
206206

207207
@Test
208208
void testIsPublicAuthEndpoint_shareLinkTokenTrailingSlash() {
209-
assertTrue(RequestUriUtils.isPublicAuthEndpoint("/share/abc123/", ""));
209+
assertTrue(
210+
RequestUriUtils.isPublicAuthEndpoint(
211+
"/share/00dcac3a-fc7a-4989-9c4f-97745484d62f/", ""));
210212
}
211213

212214
@Test
213215
void testIsPublicAuthEndpoint_shareLinkWithContextPath() {
214-
assertTrue(RequestUriUtils.isPublicAuthEndpoint("/app/share/abc123", "/app"));
216+
assertTrue(
217+
RequestUriUtils.isPublicAuthEndpoint(
218+
"/app/share/00dcac3a-fc7a-4989-9c4f-97745484d62f", "/app"));
219+
}
220+
221+
@Test
222+
void testIsPublicAuthEndpoint_shareLinkWithInvalidTokenLength() {
223+
assertFalse(RequestUriUtils.isPublicAuthEndpoint("/share/abc123", ""));
224+
assertFalse(
225+
RequestUriUtils.isPublicAuthEndpoint(
226+
"/share/00dcac3a-fc7a-4989-9c4f-97745484d62fa", ""));
215227
}
216228

217229
@Test

0 commit comments

Comments
 (0)