bito-code-review[bot] commented on code in PR #42297: URL: https://github.com/apache/superset/pull/42297#discussion_r3798792578
########## superset-frontend/scripts/bundle-size-summary.js: ########## @@ -0,0 +1,86 @@ +#!/usr/bin/env node +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +// Reduces a webpack `--json` stats file down to the handful of headline +// numbers worth tracking over time, in the flat array format +// benchmark-action/github-action-benchmark expects for its +// "customSmallerIsBetter" tool. The full stats file also includes a +// `modules`/`chunks` graph across ~15k modules, which is enormous and not +// useful for this purpose, so we only ever read `entrypoints`. +// +// Usage: node scripts/bundle-size-summary.js <path-to-stats.json> + +const fs = require('fs'); + +// Entrypoints worth tracking: the two user-facing app shells. `menu`, +// `preamble`, `theme`, and `service-worker` are small, low-variance +// infrastructure chunks, not where bundle bloat actually shows up. +const TRACKED_ENTRYPOINTS = ['spa', 'embedded']; + +function entrypointSizeByExt(entrypoint, ext) { + return (entrypoint.assets || []) + .filter(asset => asset.name.endsWith(ext)) + .reduce((total, asset) => total + asset.size, 0); +} + +function main() { + const statsPath = process.argv[2]; + if (!statsPath) { + console.error('Usage: bundle-size-summary.js <path-to-stats.json>'); + process.exit(1); + } + + const stats = JSON.parse(fs.readFileSync(statsPath, 'utf8')); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Validate fs readFileSync path argument</b></div> <div id="fix"> Security: `readFileSync` uses a non-literal path argument (`statsPath` from CLI), which could allow path traversal attacks if the script is used with untrusted input. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion if (!statsPath) { console.error('Usage: bundle-size-summary.js <path-to-stats.json>'); process.exit(1); } // Validate and sanitize the file path const path = require('path'); const resolvedPath = path.resolve(statsPath); if (!resolvedPath.endsWith('.json')) { console.error('Error: Only JSON files are allowed.'); process.exit(1); } const stats = JSON.parse(fs.readFileSync(statsPath, 'utf8')); ```` </div> </details> </div> <small><i>Code Review Run #0c5f62</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset/mcp_service/system/tool/get_schema.py: ########## @@ -235,9 +235,10 @@ async def get_schema( from superset import security_manager - if current_app.config.get("MCP_RBAC_ENABLED", True) and not ( - security_manager.can_access("can_read", class_permission) - ): + rbac_allows = not current_app.config.get( + "MCP_RBAC_ENABLED", True + ) or security_manager.can_access("can_read", class_permission) + if not (rbac_allows and _token_scope_allows("read", class_permission)): Review Comment: <div> <div id="suggestion"> <div id="issue"><b>CWE-285: RBAC Logic Bypass</b></div> <div id="fix"> The refactor changed the RBAC logic. When `MCP_RBAC_ENABLED=False`, the original code denies access (`False and not(...) = False`), but the new code may allow access depending on token scopes. This bypasses the intended feature flag behavior. ([CWE-285](https://cwe.mitre.org/data/definitions/285.html)) </div> </div> <small><i>Code Review Run #0c5f62</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/scripts/bundle-size-summary.js: ########## @@ -0,0 +1,86 @@ +#!/usr/bin/env node +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +// Reduces a webpack `--json` stats file down to the handful of headline +// numbers worth tracking over time, in the flat array format +// benchmark-action/github-action-benchmark expects for its +// "customSmallerIsBetter" tool. The full stats file also includes a +// `modules`/`chunks` graph across ~15k modules, which is enormous and not +// useful for this purpose, so we only ever read `entrypoints`. +// +// Usage: node scripts/bundle-size-summary.js <path-to-stats.json> + +const fs = require('fs'); + +// Entrypoints worth tracking: the two user-facing app shells. `menu`, +// `preamble`, `theme`, and `service-worker` are small, low-variance +// infrastructure chunks, not where bundle bloat actually shows up. +const TRACKED_ENTRYPOINTS = ['spa', 'embedded']; + +function entrypointSizeByExt(entrypoint, ext) { + return (entrypoint.assets || []) + .filter(asset => asset.name.endsWith(ext)) + .reduce((total, asset) => total + asset.size, 0); +} + +function main() { + const statsPath = process.argv[2]; + if (!statsPath) { + console.error('Usage: bundle-size-summary.js <path-to-stats.json>'); + process.exit(1); + } + + const stats = JSON.parse(fs.readFileSync(statsPath, 'utf8')); + const { entrypoints } = stats; + if (!entrypoints) { + console.error( + 'stats.json has no `entrypoints` key -- was it built with ' + + '`BUNDLE_SIZE_STATS=true` set? Without it, webpack.config.js uses ' + + '`stats: "minimal"`, which omits `entrypoints`.', + ); + process.exit(1); + } + + const results = []; + TRACKED_ENTRYPOINTS.forEach(name => { + const entrypoint = entrypoints[name]; + if (!entrypoint) { + console.error(`stats.json is missing the "${name}" entrypoint`); + process.exit(1); + } + results.push({ + name: `${name} entrypoint (JS)`, + unit: 'bytes', + value: entrypointSizeByExt(entrypoint, '.js'), + }); + results.push({ + name: `${name} entrypoint (CSS)`, + unit: 'bytes', + value: entrypointSizeByExt(entrypoint, '.css'), + }); + }); + + console.log(JSON.stringify(results, null, 2)); +} + +if (require.main === module) { + main(); +} + +module.exports = { entrypointSizeByExt, main, TRACKED_ENTRYPOINTS }; Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Missing unit tests for new tool</b></div> <div id="fix"> Add unit tests covering success paths, error scenarios, and edge cases. The script currently has no test coverage, which increases regression risk for this critical CI instrumentation. Rule [11730] requires comprehensive tests for new tools. </div> </div> <small><i>Code Review Run #0c5f62</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/scripts/bundle-size-summary.js: ########## @@ -0,0 +1,86 @@ +#!/usr/bin/env node +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +// Reduces a webpack `--json` stats file down to the handful of headline +// numbers worth tracking over time, in the flat array format +// benchmark-action/github-action-benchmark expects for its +// "customSmallerIsBetter" tool. The full stats file also includes a +// `modules`/`chunks` graph across ~15k modules, which is enormous and not +// useful for this purpose, so we only ever read `entrypoints`. +// +// Usage: node scripts/bundle-size-summary.js <path-to-stats.json> + +const fs = require('fs'); + +// Entrypoints worth tracking: the two user-facing app shells. `menu`, +// `preamble`, `theme`, and `service-worker` are small, low-variance +// infrastructure chunks, not where bundle bloat actually shows up. +const TRACKED_ENTRYPOINTS = ['spa', 'embedded']; + +function entrypointSizeByExt(entrypoint, ext) { + return (entrypoint.assets || []) + .filter(asset => asset.name.endsWith(ext)) + .reduce((total, asset) => total + asset.size, 0); +} + +function main() { + const statsPath = process.argv[2]; + if (!statsPath) { + console.error('Usage: bundle-size-summary.js <path-to-stats.json>'); + process.exit(1); + } + + const stats = JSON.parse(fs.readFileSync(statsPath, 'utf8')); + const { entrypoints } = stats; + if (!entrypoints) { + console.error( + 'stats.json has no `entrypoints` key -- was it built with ' + + '`BUNDLE_SIZE_STATS=true` set? Without it, webpack.config.js uses ' + + '`stats: "minimal"`, which omits `entrypoints`.', + ); + process.exit(1); + } + + const results = []; + TRACKED_ENTRYPOINTS.forEach(name => { + const entrypoint = entrypoints[name]; + if (!entrypoint) { + console.error(`stats.json is missing the "${name}" entrypoint`); + process.exit(1); + } Review Comment: <div> <div id="suggestion"> <div id="issue"><b>CWE-1321: Validate property access to prevent injection</b></div> <div id="fix"> Security: Dynamic property access using variable `name` on `entrypoints` object could be exploited if `TRACKED_ENTRYPOINTS` is bypassed ([CWE-1321](https://cwe.mitre.org/data/definitions/1321.html)). </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion } const results = []; TRACKED_ENTRYPOINTS.forEach(name => { if (!TRACKED_ENTRYPOINTS.includes(name)) { console.error(`Invalid entrypoint: "${name}"`); process.exit(1); } const entrypoint = entrypoints[name]; if (!entrypoint) { console.error(`stats.json is missing the "${name}" entrypoint`); process.exit(1); } ```` </div> </details> </div> <small><i>Code Review Run #0c5f62</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
