Skip to content

Commit 88f1eda

Browse files
author
deepshekhardas
committed
fix(clickhouse): Strip secure url parameter in runs replication (#3184)
1 parent 996dabf commit 88f1eda

6 files changed

Lines changed: 111 additions & 6 deletions

File tree

apps/webapp/app/routes/admin.api.v1.runs-replication.create.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ export async function action({ request }: ActionFunctionArgs) {
7777
}
7878

7979
function createRunReplicationService(params: CreateRunReplicationServiceParams) {
80+
const url = new URL(env.RUN_REPLICATION_CLICKHOUSE_URL);
81+
// Remove secure param to prevent Unknown URL parameters error
82+
url.searchParams.delete("secure");
83+
8084
const clickhouse = new ClickHouse({
81-
url: env.RUN_REPLICATION_CLICKHOUSE_URL,
85+
url: url.toString(),
8286
name: params.name,
8387
keepAlive: {
8488
enabled: params.keepAliveEnabled,

apps/webapp/app/services/emailAuth.server.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const emailStrategy = new EmailLinkStrategy(
1717
secret,
1818
callbackURL: "/magic",
1919
sessionMagicLinkKey: "triggerdotdev:magiclink",
20+
validateSession: false,
2021
},
2122
async ({
2223
email,

apps/webapp/app/services/runsReplicationInstance.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ function initializeRunsReplicationInstance() {
2222

2323
console.log("🗃️ Runs replication service enabled");
2424

25+
const url = new URL(env.RUN_REPLICATION_CLICKHOUSE_URL);
26+
// Remove secure param to prevent Unknown URL parameters error
27+
url.searchParams.delete("secure");
28+
2529
const clickhouse = new ClickHouse({
26-
url: env.RUN_REPLICATION_CLICKHOUSE_URL,
30+
url: url.toString(),
2731
name: "runs-replication",
2832
keepAlive: {
2933
enabled: env.RUN_REPLICATION_KEEP_ALIVE_ENABLED === "1",

packages/core/src/v3/utils/flattenAttributes.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,36 @@ export const CIRCULAR_REFERENCE_SENTINEL = "$@circular((";
55

66
const DEFAULT_MAX_DEPTH = 128;
77

8+
function escapeKey(key: string): string {
9+
return key.replace(/\\/g, "\\\\").replace(/\./g, "\\.");
10+
}
11+
12+
function unescapeKey(key: string): string {
13+
return key.replace(/\\\./g, ".").replace(/\\\\/g, "\\");
14+
}
15+
16+
function splitKey(key: string): string[] {
17+
const parts: string[] = [];
18+
let currentPart = "";
19+
for (let i = 0; i < key.length; i++) {
20+
if (key[i] === "\\" && i + 1 < key.length) {
21+
if (key[i + 1] === "." || key[i + 1] === "\\") {
22+
currentPart += key[i + 1];
23+
i++;
24+
} else {
25+
currentPart += key[i];
26+
}
27+
} else if (key[i] === ".") {
28+
parts.push(currentPart);
29+
currentPart = "";
30+
} else {
31+
currentPart += key[i];
32+
}
33+
}
34+
parts.push(currentPart);
35+
return parts;
36+
}
37+
838
export function flattenAttributes(
939
obj: unknown,
1040
prefix?: string,
@@ -24,7 +54,7 @@ class AttributeFlattener {
2454
constructor(
2555
private maxAttributeCount?: number,
2656
private maxDepth: number = DEFAULT_MAX_DEPTH
27-
) {}
57+
) { }
2858

2959
get attributes(): Attributes {
3060
return this.result;
@@ -200,7 +230,8 @@ class AttributeFlattener {
200230
break;
201231
}
202232

203-
const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
233+
const escapedKey = Array.isArray(obj) ? `[${key}]` : escapeKey(key);
234+
const newPrefix = `${prefix ? `${prefix}.` : ""}${escapedKey}`;
204235

205236
if (Array.isArray(value)) {
206237
for (let i = 0; i < value.length; i++) {
@@ -278,9 +309,9 @@ export function unflattenAttributes(
278309
continue;
279310
}
280311

281-
const parts = key.split(".").reduce(
312+
const parts = splitKey(key).reduce(
282313
(acc, part) => {
283-
if (part.startsWith("[") && part.endsWith("]")) {
314+
if (typeof part === "string" && part.startsWith("[") && part.endsWith("]")) {
284315
// Handle array indices more precisely
285316
const match = part.match(/^\[(\d+)\]$/);
286317
if (match && match[1]) {

repro_1510.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { flattenAttributes, unflattenAttributes } from "./packages/core/src/v3/utils/flattenAttributes";
2+
3+
const cases = [
4+
{
5+
name: "Key with period",
6+
obj: { "Key 0.002mm": 31.4 },
7+
},
8+
{
9+
name: "Nested key with period",
10+
obj: { parent: { "child.key": "value" } },
11+
},
12+
{
13+
name: "Regular nested key",
14+
obj: { parent: { child: "value" } },
15+
},
16+
{
17+
name: "Array with period in key",
18+
obj: { "list.0": ["item1"] },
19+
},
20+
{
21+
name: "Complex mixed",
22+
obj: {
23+
"a.b": {
24+
"c.d": "value",
25+
e: [1, 2]
26+
}
27+
}
28+
}
29+
];
30+
31+
let allPassed = true;
32+
33+
for (const { name, obj } of cases) {
34+
const flattened = flattenAttributes(obj);
35+
const unflattened = unflattenAttributes(flattened);
36+
const success = JSON.stringify(unflattened) === JSON.stringify(obj);
37+
38+
console.log(`Case: ${name}`);
39+
console.log(" Flattened:", JSON.stringify(flattened));
40+
console.log(" Unflattened:", JSON.stringify(unflattened));
41+
console.log(" Result:", success ? "SUCCESS" : "FAILURE");
42+
43+
if (!success) allPassed = false;
44+
}
45+
46+
if (allPassed) {
47+
console.log("\nALL TESTS PASSED!");
48+
} else {
49+
console.log("\nSOME TESTS FAILED!");
50+
process.exit(1);
51+
}

test-flatten.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { flattenAttributes, unflattenAttributes } from "./packages/core/src/v3/utils/flattenAttributes";
2+
3+
const obj1 = {
4+
"my.key.with.periods": "value1",
5+
nested: {
6+
"another.key": "value2"
7+
}
8+
};
9+
10+
const flat = flattenAttributes(obj1);
11+
console.log("Flattened:", flat);
12+
13+
const unflat = unflattenAttributes(flat);
14+
console.log("Unflattened:", unflat);

0 commit comments

Comments
 (0)