@supernova-studio/client 0.59.17 → 0.59.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.59.17",
3
+ "version": "0.59.18",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -1,3 +1,4 @@
1
1
  export * from "./figma";
2
2
  export * from "./hash";
3
3
  export * from "./query";
4
+ export * from "./redirect-validation";
@@ -0,0 +1,76 @@
1
+ export const exhaustiveInvalidUriPaths = {
2
+ emptyPath: "",
3
+ spacesInPath: "/invalid path/with spaces",
4
+ specialCharacter1: "/path/with|invalid>characters",
5
+ specialCharacter2: "/path/with<invalid*characters",
6
+ specialCharacter3: "/path/{invalid}?characters",
7
+ consecutiveSlashes: "/path//with///too/many/slashes",
8
+ unencodedPercent: "/path/with/unencoded%percent",
9
+ unencodedSpaces: "/path/with unencoded spaces",
10
+ fragmentIdentifier: "/path/with#fragment",
11
+ queryParameters: "/path/with?query=parameter",
12
+ nullCharacter: "/path/with/\u0000nullcharacter",
13
+ onlySlash: "/",
14
+ controlCharacter: "/path/with/control\0character",
15
+ extremelyLongPath: "/" + "a".repeat(2047),
16
+ invalidStartCharacter: "///path/starting/with/slashes",
17
+ invalidStartCharacterColon: ":/path/starting/with/colon",
18
+ invalidTrailingDot: "/path/ending/with/dot.",
19
+ invalidPercentEncoding1: "/path/with/%2",
20
+ invalidPercentEncoding2: "/path/with/%ZZ",
21
+ invalidPercentEncoding3: "/path/with/%G1",
22
+ reservedCharacter1: "/path/with?<reserved>",
23
+ reservedCharacter2: '/path/with/"quotes"',
24
+ reservedCharacter3: "/path/with/[brackets]",
25
+ reservedCharacter4: "/path/with/\\backslashes",
26
+ nonAscii1: "/path/with/你好",
27
+ nonAscii2: "/path/with/emoji/😃",
28
+ mixedEncodingPath: "/path/%41A%42B%C3%28",
29
+ directoryTraversal1: "/path/../../etc/passwd",
30
+ directoryTraversal2: "/path/./././",
31
+ };
32
+
33
+ type ValidationErrorReason = "TooLong" | "InvalidURI" | "Empty" | "ContainsQuery" | "ContainsFragment";
34
+
35
+ export function isValidRedirectPath(path: string): { isValid: boolean; reason: ValidationErrorReason | undefined } {
36
+ const trimmedPath = path.toLowerCase().trim();
37
+ const url = "https://www.example.com" + trimmedPath;
38
+ if (url.length > 2048) {
39
+ return {
40
+ isValid: false,
41
+ reason: "TooLong",
42
+ };
43
+ }
44
+ if (trimmedPath === "") {
45
+ return {
46
+ isValid: false,
47
+ reason: "Empty",
48
+ };
49
+ }
50
+ if (url === "/") {
51
+ return {
52
+ isValid: false,
53
+ reason: "Empty",
54
+ };
55
+ }
56
+
57
+ if (url.includes("?")) {
58
+ return {
59
+ isValid: false,
60
+ reason: "ContainsQuery",
61
+ };
62
+ }
63
+ if (url.includes("#")) {
64
+ return {
65
+ isValid: false,
66
+ reason: "ContainsFragment",
67
+ };
68
+ }
69
+
70
+ const regex = /^\/[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/;
71
+ const isValid = regex.test(trimmedPath);
72
+ return {
73
+ isValid: regex.test(trimmedPath),
74
+ reason: !isValid ? "InvalidURI" : undefined,
75
+ };
76
+ }