@@ -6,9 +6,11 @@ module.exports = async function (deps) {
66 const jarPath = path . join ( microbotDir , `microbot-${ version } .jar` ) ;
77 const commandArgs = [ '-jar' , jarPath ] ;
88
9- if ( proxy && proxy . proxyIp && proxy . proxyType ) {
10- commandArgs . push ( `-proxy=${ proxy . proxyIp } ` ) ;
11- commandArgs . push ( `-proxy-type=${ proxy . proxyType } ` ) ;
9+ // apply proxy args (done differently depending on client version)
10+ const err = addProxyArgs ( commandArgs , version , proxy ) ;
11+ if ( err ) {
12+ log . error ( err . message ) ;
13+ return { error : err . message } ;
1214 }
1315
1416 if ( account && account . profile ) {
@@ -36,9 +38,11 @@ module.exports = async function (deps) {
3638 const jarPath = path . join ( microbotDir , `microbot-${ version } .jar` ) ;
3739 const commandArgs = [ '-jar' , jarPath , '-clean-jagex-launcher' ] ;
3840
39- if ( proxy && proxy . proxyIp && proxy . proxyType ) {
40- commandArgs . push ( `-proxy=${ proxy . proxyIp } ` ) ;
41- commandArgs . push ( `-proxy-type=${ proxy . proxyType } ` ) ;
41+ // apply proxy args (done differently depending on client version)
42+ const err = addProxyArgs ( commandArgs , version , proxy ) ;
43+ if ( err ) {
44+ log . error ( err . message ) ;
45+ return { error : err . message } ;
4246 }
4347
4448 if (
@@ -119,8 +123,111 @@ module.exports = async function (deps) {
119123 }
120124 }
121125
126+ /**
127+ * Adds proxy arguments to the commandArgs array.
128+ * For versions < 1.9.9.2 we keep the old behavior: -proxy=<ip[:port]> -proxy-type=<type>
129+ * For versions >= 1.9.9.2 we only support SOCKS proxies in the following form: scheme://[user:pass@]host:port
130+ * Accepted legacy input formats (proxy.proxyIp):
131+ * ip:port
132+ * ip:port:user:pass (password may contain colons; extra segments are joined back for password)
133+ * scheme://user:pass@host:port (already formatted; passed through unchanged)
134+ * We do not push -proxy-type for new versions.
135+ *
136+ * @param {string[] } commandArgs - The command arguments array.
137+ * @param {string } version - The client version (e.g. "1.9.9.1").
138+ * @param {Object } proxy - The proxy configuration object.
139+ * @returns {Error|null } - Returns an error if the proxy configuration is invalid, otherwise null.
140+ */
141+ function addProxyArgs ( commandArgs , version , proxy ) {
142+ if ( ! proxy || ! proxy . proxyIp ) return null ;
143+ if ( typeof proxy . proxyIp !== 'string' ) return null ;
144+ if ( proxy . proxyIp . trim ( ) === '' ) return null ;
145+
146+ const isNewFormat =
147+ version . localeCompare ( '1.9.9.2' , undefined , { numeric : true } ) >= 0 ;
148+
149+ if ( ! isNewFormat ) {
150+ // Backwards compatibility: keep existing arguments exactly as before
151+ if ( proxy . proxyType ) {
152+ commandArgs . push ( `-proxy=${ proxy . proxyIp } ` ) ;
153+ commandArgs . push ( `-proxy-type=${ proxy . proxyType } ` ) ;
154+ }
155+ return null ;
156+ }
157+
158+ // If <proxy.proxyType> is set and it's not socks we error and return
159+ if ( proxy . proxyType && proxy . proxyType !== 'socks' ) {
160+ return new Error (
161+ 'Only SOCKS proxies are supported since client version 1.9.9.2. Found: ' +
162+ proxy . proxyType
163+ ) ;
164+ }
165+
166+ // New format (>= 1.9.9.2) – only SOCKS proxies supported.
167+ // As the UI may be changed in the future, we need to be flexible with input formats.
168+ try {
169+ let raw = proxy . proxyIp . trim ( ) ;
170+ // if user already supplied in URI format, just use it.
171+ if ( raw . includes ( '://' ) ) {
172+ commandArgs . push ( `-proxy=${ raw } ` ) ;
173+ return null ;
174+ }
175+
176+ const DEFAULT_SCHEME = 'socks5' ;
177+ const parts = raw . split ( ':' ) ;
178+
179+ if ( parts . length === 2 ) {
180+ const [ host , port ] = parts ;
181+ commandArgs . push ( `-proxy=${ DEFAULT_SCHEME } ://${ host } :${ port } ` ) ;
182+ } else if ( parts . length >= 4 ) {
183+ const host = parts [ 0 ] ;
184+ const port = parts [ 1 ] ;
185+ const user = parts [ 2 ] ;
186+ const pass = parts . slice ( 3 ) . join ( ':' ) ; // allow colons in password
187+ // encode user and pass (without encoding things may break)
188+ const encUser = encodeURIComponent ( user ) ;
189+ const encPass = encodeURIComponent ( pass ) ;
190+ commandArgs . push (
191+ `-proxy=${ DEFAULT_SCHEME } ://${ encUser } :${ encPass } @${ host } :${ port } `
192+ ) ;
193+ } else {
194+ // fallback: just attach whatever (may be just host)
195+ commandArgs . push ( `-proxy=${ DEFAULT_SCHEME } ://${ raw } ` ) ;
196+ }
197+ } catch ( err ) {
198+ return new Error (
199+ 'Failed to construct new proxy URI: ' + err . message
200+ ) ;
201+ }
202+ return null ;
203+ }
204+
205+ /**
206+ * Redacts sensitive information from command line arguments.
207+ * @param {string[] } args - The command line arguments.
208+ * @returns {string[] } - The redacted command line arguments.
209+ */
210+ function redactCommandArgs ( args ) {
211+ return args . map ( ( a ) => {
212+ if ( ! a . startsWith ( '-proxy=' ) ) return a ;
213+ const value = a . slice ( '-proxy=' . length ) ;
214+ try {
215+ const u = new URL ( value ) ;
216+ if ( u . username || u . password ) {
217+ if ( u . username ) u . username = '***' ;
218+ if ( u . password ) u . password = '***' ;
219+ return `-proxy=${ u . toString ( ) } ` ;
220+ }
221+ } catch ( _ ) {
222+ // fallback: strip credentials if present
223+ return `-proxy=${ value . replace ( / \/ \/ [ ^ @ ] * @ / , '//***@' ) } ` ;
224+ }
225+ return a ;
226+ } ) ;
227+ }
228+
122229 function executeJar ( commandArgs , dialog ) {
123- log . info ( `java ${ commandArgs . join ( ' ' ) } ` ) ;
230+ log . info ( `java ${ redactCommandArgs ( commandArgs ) . join ( ' ' ) } ` ) ;
124231
125232 /**
126233 * Additional arguments for spawn library.
@@ -191,7 +298,8 @@ module.exports = async function (deps) {
191298 }
192299
193300 function checkJavaAndRunJar ( commandArgs , dialog , shell ) {
194- log . info ( `java ${ commandArgs . join ( ' ' ) } ` ) ;
301+ log . info ( `java ${ redactCommandArgs ( commandArgs ) . join ( ' ' ) } ` ) ;
302+
195303 isJavaInstalled ( ( isInstalled , error ) => {
196304 if ( isInstalled ) {
197305 log . info ( 'Java is installed, running the JAR...' ) ;
0 commit comments