File tree Expand file tree Collapse file tree 7 files changed +261
-55
lines changed
Expand file tree Collapse file tree 7 files changed +261
-55
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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+
4666export 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
88109export type ResourceAccessToken = {
@@ -95,4 +116,4 @@ export type ResourceAccessToken = {
95116 title : string | null ;
96117 description : string | null ;
97118 createdAt : number ;
98- } ;
119+ } ;
You can’t perform that action at this time.
0 commit comments