File tree 4 files changed +38
-2
lines changed
ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceInitForm
ClientInstancePage/modals/UpdateInstanceModal/components
4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ const en = {
54
54
'Configuration for instance {instance: string} has changed. Disconnect from all locations to apply changes.' ,
55
55
deadConDropped :
56
56
'Detected that the {con_type: string} {interface_name: string} has disconnected, trying to reconnect...' ,
57
+ noCookie : 'No defguard_proxy set-cookie received' ,
57
58
} ,
58
59
} ,
59
60
components : {
Original file line number Diff line number Diff line change @@ -165,6 +165,10 @@ type RootTranslation = {
165
165
* @param {string } interface_name
166
166
*/
167
167
deadConDropped : RequiredParams < 'con_type' | 'interface_name' >
168
+ /**
169
+ * No defguard_proxy set-cookie received
170
+ */
171
+ noCookie : string
168
172
}
169
173
}
170
174
components : {
@@ -1762,6 +1766,10 @@ export type TranslationFunctions = {
1762
1766
* Detected that the {con_type} {interface_name} has disconnected, trying to reconnect...
1763
1767
*/
1764
1768
deadConDropped : ( arg : { con_type : string , interface_name : string } ) => LocalizedString
1769
+ /**
1770
+ * No defguard_proxy set-cookie received
1771
+ */
1772
+ noCookie : ( ) => LocalizedString
1765
1773
}
1766
1774
}
1767
1775
components : {
Original file line number Diff line number Diff line change @@ -102,7 +102,6 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => {
102
102
body : Body . json ( data ) ,
103
103
} )
104
104
. then ( async ( res : Response < EnrollmentStartResponse | EnrollmentError > ) => {
105
- const authCookie = res . headers [ 'set-cookie' ] ;
106
105
if ( ! res . ok ) {
107
106
setIsLoading ( false ) ;
108
107
error ( JSON . stringify ( res . data ) ) ;
@@ -122,6 +121,24 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => {
122
121
}
123
122
}
124
123
}
124
+ // There may be other set-cookies, set by e.g. a proxy
125
+ // Get only the defguard_proxy cookie
126
+ const authCookie = res . rawHeaders [ 'set-cookie' ] . find ( ( cookie ) =>
127
+ cookie . startsWith ( 'defguard_proxy=' ) ,
128
+ ) ;
129
+ if ( ! authCookie ) {
130
+ setIsLoading ( false ) ;
131
+ error (
132
+ LL . common . messages . errorWithMessage ( {
133
+ message : LL . common . messages . noCookie ( ) ,
134
+ } ) ,
135
+ ) ;
136
+ throw Error (
137
+ LL . common . messages . errorWithMessage ( {
138
+ message : LL . common . messages . noCookie ( ) ,
139
+ } ) ,
140
+ ) ;
141
+ }
125
142
debug ( 'Response received with status OK' ) ;
126
143
const r = res . data as EnrollmentStartResponse ;
127
144
// get client registered instances
Original file line number Diff line number Diff line change @@ -108,7 +108,17 @@ export const UpdateInstanceModalForm = () => {
108
108
proxy_api_url = proxy_api_url + '/api/v1' ;
109
109
const instance = clientInstances . find ( ( i ) => i . uuid === enrollmentData . instance . id ) ;
110
110
if ( instance ) {
111
- const authCookie = res . headers [ 'set-cookie' ] ;
111
+ const authCookie = res . rawHeaders [ 'set-cookie' ] . find ( ( cookie ) =>
112
+ cookie . startsWith ( 'defguard_proxy=' ) ,
113
+ ) ;
114
+ if ( ! authCookie ) {
115
+ toaster . error (
116
+ LL . common . messages . errorWithMessage ( {
117
+ message : LL . common . messages . noCookie ( ) ,
118
+ } ) ,
119
+ ) ;
120
+ return ;
121
+ }
112
122
headers [ 'Cookie' ] = authCookie ;
113
123
const instanceInfoResponse = await fetch < CreateDeviceResponse > (
114
124
`${ proxy_api_url } /enrollment/network_info` ,
You can’t perform that action at this time.
0 commit comments