Skip to content

Commit 819cc94

Browse files
Update to bring down features from pangolin
1 parent 4d5ff8d commit 819cc94

File tree

7 files changed

+261
-55
lines changed

7 files changed

+261
-55
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@types/js-yaml": "4.0.9",
4747
"@types/node": "24.9.1",
4848
"@types/pg": "8.15.5",
49+
"@types/semver": "7.7.1",
4950
"@types/ws": "8.18.1",
5051
"esbuild": "0.25.11",
5152
"esbuild-node-externals": "1.18.0",

server/lib/asn.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import logger from "@server/logger";
2+
import axios from "axios";
3+
import config from "./config";
4+
import { tokenManager } from "./tokenManager";
5+
6+
export async function remoteGetASNForIp(
7+
ip: string
8+
): Promise<number | undefined> {
9+
try {
10+
const response = await axios.get(
11+
`${config.getRawConfig().managed?.endpoint}/api/v1/hybrid/asnip/${ip}`,
12+
await tokenManager.getAuthHeader()
13+
);
14+
15+
return response.data.data.asn;
16+
} catch (error) {
17+
if (axios.isAxiosError(error)) {
18+
logger.error("Error fetching config in verify session:", {
19+
message: error.message,
20+
code: error.code,
21+
status: error.response?.status,
22+
statusText: error.response?.statusText,
23+
url: error.config?.url,
24+
method: error.config?.method
25+
});
26+
} else {
27+
logger.error("Error fetching config in verify session:", error);
28+
}
29+
}
30+
31+
return;
32+
}

server/lib/checkOrgAccessPolicy.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Org, ResourceSession } from "./types";
2+
3+
export function enforceResourceSessionLength(
4+
resourceSession: ResourceSession,
5+
org: Org
6+
): { valid: boolean; error?: string } {
7+
if (org.maxSessionLengthHours) {
8+
const sessionIssuedAt = resourceSession.issuedAt; // may be null
9+
const maxSessionLengthHours = org.maxSessionLengthHours;
10+
11+
if (sessionIssuedAt) {
12+
const maxSessionLengthMs = maxSessionLengthHours * 60 * 60 * 1000;
13+
const sessionAgeMs = Date.now() - sessionIssuedAt;
14+
15+
if (sessionAgeMs > maxSessionLengthMs) {
16+
return {
17+
valid: false,
18+
error: `Resource session has expired due to organization policy (max session length: ${maxSessionLengthHours} hours)`
19+
};
20+
}
21+
} else {
22+
return {
23+
valid: false,
24+
error: `Resource session is invalid due to organization policy (max session length: ${maxSessionLengthHours} hours)`
25+
};
26+
}
27+
}
28+
29+
return { valid: true };
30+
}

server/lib/types.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ export type ResourceHeaderAuth = {
4343
headerAuthHash: string;
4444
};
4545

46+
export type ResourceHeaderAuthExtendedCompatibility = {
47+
resourceId: number;
48+
headerAuthExtendedCompatibilityId: number;
49+
extendedCompatibilityIsActivated: boolean;
50+
}
51+
52+
export type Org = {
53+
name: string;
54+
orgId: string;
55+
subnet: string | null;
56+
utilitySubnet: string | null;
57+
createdAt: string | null;
58+
requireTwoFactor: boolean | null;
59+
maxSessionLengthHours: number | null;
60+
passwordExpiryDays: number | null;
61+
settingsLogRetentionDaysRequest: number;
62+
settingsLogRetentionDaysAccess: number;
63+
settingsLogRetentionDaysAction: number;
64+
}
65+
4666
export type LoginPage = {
4767
loginPageId: number;
4868
subdomain: string | null;
@@ -83,6 +103,7 @@ export type ResourceSession = {
83103
accessTokenId: string | null;
84104
isRequestToken: boolean;
85105
userSessionId: string | null;
106+
issuedAt: number | null;
86107
};
87108

88109
export type ResourceAccessToken = {
@@ -95,4 +116,4 @@ export type ResourceAccessToken = {
95116
title: string | null;
96117
description: string | null;
97118
createdAt: number;
98-
};
119+
};

0 commit comments

Comments
 (0)