-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(schema-compiler): Use join hints from views for join graph #10006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fix/join-paths
Are you sure you want to change the base?
Conversation
const to = hint[i + 1]; | ||
|
||
if (tunedNodes[from]?.[to] !== undefined) { | ||
tunedNodes[from][to] = PRIORITY_WEIGHT; |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 days ago
To fix this vulnerability, we must ensure that keys assigned to tunedNodes
(specifically, from
and to
) are filtered such that prototype-polluting keys like __proto__
, constructor
, and prototype
cannot be used as object property names.
The single best way to do this is within the loops constructing and mutating tunedNodes
. Before any assignment to an object with a computed property name, add a conditional check such that if the key is one of the dangerous property names, skip or throw an error.
The only file to change is packages/cubejs-schema-compiler/src/compiler/JoinGraph.ts
. We will alter two places in getFixedWeightsGraph
:
- On building the deep copy (
tunedNodes[from] = {}
andtunedNodes[from][to] = weight;
) - On updating the weight (
tunedNodes[from][to] = PRIORITY_WEIGHT;
)
However, the primary risk is on the assignment involving potentially tainted input, which happens in the join hints loop — that's what CodeQL flagged. We'll filter from
and to
in the hint-processing loop.
No external dependencies are needed.
-
Copy modified lines R293-R295 -
Copy modified line R299 -
Copy modified line R302 -
Copy modified line R308
@@ -290,11 +290,16 @@ | ||
protected getFixedWeightsGraph(joinHints: JoinHints): Graph { | ||
const PRIORITY_WEIGHT = 20; // Lower weight for preferred paths | ||
|
||
// Keys that can pollute object prototype | ||
const POLLUTING_KEYS = ['__proto__', 'constructor', 'prototype']; | ||
|
||
// Create a deep copy of this.nodes to avoid modifying the original | ||
const tunedNodes: Record<string, Record<string, number>> = {}; | ||
for (const [from, destinations] of Object.entries(this.nodes)) { | ||
if (POLLUTING_KEYS.includes(from)) continue; // prevent prototype pollution | ||
tunedNodes[from] = {}; | ||
for (const [to, weight] of Object.entries(destinations)) { | ||
if (POLLUTING_KEYS.includes(to)) continue; // prevent prototype pollution | ||
tunedNodes[from][to] = weight; | ||
} | ||
} | ||
@@ -305,7 +305,7 @@ | ||
for (let i = 0; i < hint.length - 1; i++) { | ||
const from = hint[i]; | ||
const to = hint[i + 1]; | ||
|
||
if (POLLUTING_KEYS.includes(from) || POLLUTING_KEYS.includes(to)) continue; // prevent prototype pollution | ||
if (tunedNodes[from]?.[to] !== undefined) { | ||
tunedNodes[from][to] = PRIORITY_WEIGHT; | ||
} |
c4ad9ee
to
059ec95
Compare
linter hint
This reverts commit e79dc0d.
84c87de
to
869b651
Compare
This PR updates join graph for the query construction by prioritizing hints from view definitions.
This fixes #9852
Temporarily set against fix/join-paths as a parent. I'll switch to the master after the merge.
Check List