codeant-ai-for-open-source[bot] commented on code in PR #45997: URL: https://github.com/apache/superset/pull/45997#discussion_r4463621607
########## superset-frontend/src/features/databases/DatabaseModal/SecureExtraHints.tsx: ########## @@ -0,0 +1,238 @@ +/** + * 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. + */ +import { useEffect, useRef, useState } from 'react'; +import { t } from '@apache-superset/core/translation'; +import { Alert } from '@apache-superset/core/components'; +import { css, SupersetTheme } from '@apache-superset/core/theme'; +import { SupersetClient } from '@superset-ui/core'; +import { Button, Icons, Input, Tooltip } from '@superset-ui/core/components'; +import { EncryptedExtraHint, EncryptedExtraSecretField } from '../types'; +import { StyledInputContainer } from './styles'; + +const BULLETS = '•'.repeat(20); +const MASK = 'XXXXXXXXXX'; + +// StyledInputContainer borders every text input; inside the affix wrapper +// that would draw a second box, so restore antd's affixed input defaults. +// Inter's contextual alternates would restyle the bullets before the suffix. +const INPUT_STYLES = { + input: { borderWidth: 0, padding: 0, fontVariantLigatures: 'no-contextual' }, +}; + +// Same colours as antd's password field eye. +const eyeIconStyles = (theme: SupersetTheme) => css` + color: ${theme.colorIcon}; + &:hover { + color: ${theme.colorIconHover}; + } +`; + +const isRecord = (value: unknown): value is Record<string, unknown> => + typeof value === 'object' && value !== null && !Array.isArray(value); + +/** + * Lists the masked values of a Secure extra JSON that sit at the engine's + * declared sensitive paths (`$.a.b`, with `*` matching every key of a level). + */ +export const resolveMaskedSecretFields = ( + maskedEncryptedExtra: string | undefined, + sensitiveFields: Record<string, string>, +): EncryptedExtraSecretField[] => { + let payload: unknown; + try { + payload = JSON.parse(maskedEncryptedExtra ?? ''); + } catch { + return []; + } + const fields = new Map<string, string>(); + Object.entries(sensitiveFields).forEach(([declared, label]) => { + let matches: [string, unknown][] = [['$', payload]]; + declared + .split('.') + .slice(1) + .forEach(segment => { + matches = matches.flatMap(([path, value]): [string, unknown][] => { + if (!isRecord(value)) { + return []; + } + return segment === '*' + ? Object.entries(value).map(([key, child]) => [ + `${path}.${key}`, + child, + ]) + : [[`${path}.${segment}`, value[segment]]]; + }); + }); + matches.forEach(([path, value]) => { Review Comment: **Suggestion:** `resolveMaskedSecretFields` treats each JSONPath segment as an object key, so valid array-index or bracket-key paths do not match masks and their hint fields are omitted. **Assessment:** 🟠 `Major` · 🔁 `Occurrence: Rarely` · 🏷️ `Api mismatch` [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=dcccdaad664640cf951e5c42d7229b92&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=dcccdaad664640cf951e5c42d7229b92&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/src/features/databases/DatabaseModal/SecureExtraHints.tsx **Line:** 66:82 **Comment:** *Api Mismatch: `resolveMaskedSecretFields` treats each JSONPath segment as an object key, so valid array-index or bracket-key paths do not match masks and their hint fields are omitted. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45997&comment_hash=a989eb288640d9b8bea49e6d4a1aa5e4a819b5eb665f0216a17de104ff348bb8&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45997&comment_hash=a989eb288640d9b8bea49e6d4a1aa5e4a819b5eb665f0216a17de104ff348bb8&reaction=dislike'>👎</a> ########## superset-frontend/src/features/databases/DatabaseModal/SecureExtraHints.tsx: ########## @@ -0,0 +1,238 @@ +/** + * 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. + */ +import { useEffect, useRef, useState } from 'react'; +import { t } from '@apache-superset/core/translation'; +import { Alert } from '@apache-superset/core/components'; +import { css, SupersetTheme } from '@apache-superset/core/theme'; +import { SupersetClient } from '@superset-ui/core'; +import { Button, Icons, Input, Tooltip } from '@superset-ui/core/components'; +import { EncryptedExtraHint, EncryptedExtraSecretField } from '../types'; +import { StyledInputContainer } from './styles'; + +const BULLETS = '•'.repeat(20); +const MASK = 'XXXXXXXXXX'; + +// StyledInputContainer borders every text input; inside the affix wrapper +// that would draw a second box, so restore antd's affixed input defaults. +// Inter's contextual alternates would restyle the bullets before the suffix. +const INPUT_STYLES = { + input: { borderWidth: 0, padding: 0, fontVariantLigatures: 'no-contextual' }, +}; + +// Same colours as antd's password field eye. +const eyeIconStyles = (theme: SupersetTheme) => css` + color: ${theme.colorIcon}; + &:hover { + color: ${theme.colorIconHover}; + } +`; + +const isRecord = (value: unknown): value is Record<string, unknown> => + typeof value === 'object' && value !== null && !Array.isArray(value); + +/** + * Lists the masked values of a Secure extra JSON that sit at the engine's + * declared sensitive paths (`$.a.b`, with `*` matching every key of a level). + */ +export const resolveMaskedSecretFields = ( + maskedEncryptedExtra: string | undefined, + sensitiveFields: Record<string, string>, +): EncryptedExtraSecretField[] => { + let payload: unknown; + try { + payload = JSON.parse(maskedEncryptedExtra ?? ''); + } catch { + return []; + } + const fields = new Map<string, string>(); + Object.entries(sensitiveFields).forEach(([declared, label]) => { + let matches: [string, unknown][] = [['$', payload]]; + declared + .split('.') + .slice(1) + .forEach(segment => { + matches = matches.flatMap(([path, value]): [string, unknown][] => { + if (!isRecord(value)) { + return []; + } + return segment === '*' + ? Object.entries(value).map(([key, child]) => [ + `${path}.${key}`, + child, + ]) + : [[`${path}.${segment}`, value[segment]]]; + }); + }); + matches.forEach(([path, value]) => { + if (value === MASK && !fields.has(path)) { + fields.set(path, label); + } + }); + }); + return Array.from(fields, ([path, label]) => ({ path, label })); +}; + +type HintsState = + | { status: 'idle' } + | { status: 'loading' } + | { status: 'loaded'; hints: EncryptedExtraHint[] } + | { status: 'error' }; + +const SecureExtraHints = ({ + databaseId, + fields, + minLength, +}: { + databaseId: number; + fields: EncryptedExtraSecretField[]; + // Shortest secret whose ending the server reveals. + minLength: number; +}) => { + const [state, setState] = useState<HintsState>({ status: 'idle' }); + const inFlight = useRef(false); + const mounted = useRef(true); + + // Set on every run: strict mode and fast refresh rerun effects after cleanup. + useEffect(() => { + mounted.current = true; + return () => { + mounted.current = false; + }; + }, []); + + const fetchHints = () => { + if (inFlight.current) { + return; + } + inFlight.current = true; + setState({ status: 'loading' }); + SupersetClient.get({ + endpoint: `/api/v1/database/${databaseId}/encrypted_extra_hints/`, + }) + .then(({ json }) => { + if (mounted.current) { + setState({ status: 'loaded', hints: json?.result ?? [] }); + } + }) Review Comment: **Suggestion:** `databaseId` can change while this component stays mounted, letting an old response populate hints for the new database and show the previous database’s suffix at a matching path. **Assessment:** 🟠 `Major` · 🔁 `Occurrence: Rarely` · 🏷️ `Stale reference` [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d7270de6419c49daa35bc27530eb17d9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d7270de6419c49daa35bc27530eb17d9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/src/features/databases/DatabaseModal/SecureExtraHints.tsx **Line:** 128:132 **Comment:** *Stale Reference: `databaseId` can change while this component stays mounted, letting an old response populate hints for the new database and show the previous database’s suffix at a matching path. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45997&comment_hash=4e59c9991d853d0c19653f93955bded2a11b4757d87e6aaa67ea8712d2c93b75&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45997&comment_hash=4e59c9991d853d0c19653f93955bded2a11b4757d87e6aaa67ea8712d2c93b75&reaction=dislike'>👎</a> -- 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]
