File tree Expand file tree Collapse file tree
apps/sim/tools/elasticsearch Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,23 @@ describe('parseCloudId', () => {
6262 expect ( ( ) => parseCloudId ( hostile ) ) . toThrow ( / I n v a l i d C l o u d I D / )
6363 } )
6464
65+ it ( 'rejects a malformed parent-domain port even when the service port is valid' , ( ) => {
66+ const hostile = cloudId ( `${ PARENT_DOMAIN } :abc$${ ES_UUID } :9243$${ KIBANA_UUID } ` )
67+ expect ( ( ) => parseCloudId ( hostile ) ) . toThrow ( / I n v a l i d C l o u d I D / )
68+ } )
69+
70+ /**
71+ * `extractPortFromName` splits at the last colon, so a second colon survives
72+ * in the *name* half, where the `#@?/\` reject set does not catch it. Left
73+ * unchecked this builds `https://<uuid>.<host>:<port>:<port>`, which throws a
74+ * bare `TypeError: Invalid URL` inside the transport instead of naming the
75+ * real problem.
76+ */
77+ it ( 'rejects a second colon in the parent domain rather than building an invalid authority' , ( ) => {
78+ const hostile = cloudId ( `${ PARENT_DOMAIN } :9243:evil@x$${ ES_UUID } :9243$${ KIBANA_UUID } ` )
79+ expect ( ( ) => parseCloudId ( hostile ) ) . toThrow ( / I n v a l i d C l o u d I D / )
80+ } )
81+
6582 it ( 'rejects a payload with fewer than three $-separated components' , ( ) => {
6683 expect ( ( ) => parseCloudId ( cloudId ( `${ PARENT_DOMAIN } $${ ES_UUID } ` ) ) ) . toThrow ( / I n v a l i d C l o u d I D / )
6784 } )
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ const DEFAULT_CLOUD_PORT = '443'
1313 * Mirrors the `strings.IndexAny(component, "#@?/")` reject set in Beats, plus
1414 * `\`, which the WHATWG URL parser treats as a path separator for special
1515 * schemes and which therefore truncates the authority exactly as `/` does.
16+ *
17+ * A `:` is deliberately absent — `extractPortFromName` has already split each
18+ * component at its last colon, so a surviving colon means a second one, which
19+ * the all-digits port check below rejects.
1620 */
1721const CLOUD_ID_REJECTED_CHARACTERS = / [ # @ ? / \\ ] /
1822
@@ -59,8 +63,10 @@ export function parseCloudId(cloudId: string): string {
5963 }
6064 }
6165
62- if ( ! / ^ \d + $ / . test ( elasticsearch . port ) ) {
63- throw new Error ( 'Invalid Cloud ID format' )
66+ for ( const port of [ parentDomain . port , elasticsearch . port ] ) {
67+ if ( ! / ^ \d + $ / . test ( port ) ) {
68+ throw new Error ( 'Invalid Cloud ID format' )
69+ }
6470 }
6571
6672 const host = `${ elasticsearch . name } .${ parentDomain . name } `
You can’t perform that action at this time.
0 commit comments