github-advanced-security[bot] commented on code in PR #35021: URL: https://github.com/apache/superset/pull/35021#discussion_r2873196777
########## superset-frontend/src/pages/RedirectWarning/utils.ts: ########## @@ -0,0 +1,94 @@ +/** + * 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. + */ + +const TRUSTED_URLS_KEY = 'superset_trusted_urls'; +const MAX_TRUSTED_URLS = 100; +const ALLOWED_SCHEMES = ['http:', 'https:']; + +/** + * Normalize a URL for comparison (origin + path without trailing slash + search). + */ +function normalizeUrl(url: string): string { + try { + const parsed = new URL(url); + return parsed.origin + parsed.pathname.replace(/\/$/, '') + parsed.search; + } catch { + return url; + } +} + +/** + * Return true if the URL scheme is safe for navigation. + * Blocks javascript:, data:, vbscript:, file:, etc. + */ +export function isAllowedScheme(url: string): boolean { + try { + const parsed = new URL(url); + return ALLOWED_SCHEMES.includes(parsed.protocol); + } catch { + // relative URLs or unparseable — allow (they'll resolve against current origin) + return true; + } +} + +/** + * Read the target URL from the current page's query string. + * + * URLSearchParams.get() already percent-decodes the value, so we must NOT + * call decodeURIComponent again (doing so would allow double-encoded + * payloads like `javascript%253Aalert(1)` to bypass scheme checks). + */ +export function getTargetUrl(): string { + const params = new URLSearchParams(window.location.search); + const url = params.get('url') ?? ''; + return url.trim(); +} + +function getTrustedUrls(): string[] { + try { + const stored = localStorage.getItem(TRUSTED_URLS_KEY); + return stored ? JSON.parse(stored) : []; + } catch { + return []; + } +} + +function saveTrustedUrls(urls: string[]): void { + const limited = + urls.length > MAX_TRUSTED_URLS ? urls.slice(-MAX_TRUSTED_URLS) : urls; + try { + localStorage.setItem(TRUSTED_URLS_KEY, JSON.stringify(limited)); Review Comment: ## Clear text storage of sensitive information This stores sensitive data returned by [a call to getTrustedUrls](1) as clear text. This stores sensitive data returned by [an access to trusted](2) as clear text. [Show more details](https://github.com/apache/superset/security/code-scanning/2239) ########## superset-frontend/src/pages/RedirectWarning/index.tsx: ########## @@ -0,0 +1,183 @@ +/** + * 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 { useState, useMemo, useCallback } from 'react'; +import { t } from '@superset-ui/core'; +import { css, styled, useTheme } from '@apache-superset/core/ui'; +import { + Button, + Card, + Checkbox, + Flex, + Typography, +} from '@superset-ui/core/components'; +import { Icons } from '@superset-ui/core/components/Icons'; +import { + getTargetUrl, + isUrlTrusted, + trustUrl, + isAllowedScheme, +} from './utils'; + +const PageContainer = styled(Flex)` + ${({ theme }) => css` + height: calc(100vh - 64px); + background-color: ${theme.colorBgLayout}; + padding: ${theme.padding}px; + `} +`; + +const WarningCard = styled(Card)` + ${({ theme }) => css` + max-width: 520px; + width: 100%; + box-shadow: ${theme.boxShadowSecondary}; + `} +`; + +const WarningHeader = styled(Flex)` + ${({ theme }) => css` + padding: ${theme.paddingLG}px ${theme.paddingXL}px; + border-bottom: 1px solid ${theme.colorBorderSecondary}; + `} +`; + +const WarningBody = styled.div` + ${({ theme }) => css` + padding: ${theme.paddingXL}px; + `} +`; + +const UrlDisplay = styled(Flex)` + ${({ theme }) => css` + background-color: ${theme.colorFillQuaternary}; + border-radius: ${theme.borderRadiusSM}px; + padding: ${theme.paddingSM}px ${theme.padding}px; + margin-bottom: ${theme.margin}px; + `} +`; + +const UrlText = styled(Typography.Text)` + ${({ theme }) => css` + font-family: ${theme.fontFamilyCode}; + font-size: ${theme.fontSize}px; + word-break: break-all; + `} +`; + +const WarningFooter = styled(Flex)` + ${({ theme }) => css` + padding: ${theme.padding}px ${theme.paddingXL}px; + background-color: ${theme.colorFillAlter}; + border-top: 1px solid ${theme.colorBorderSecondary}; + `} +`; + +const WarningTitle = styled(Typography.Title)` + && { + margin: 0; + } +`; + +export default function RedirectWarning() { + const theme = useTheme(); + const [trustChecked, setTrustChecked] = useState(false); + + const targetUrl = useMemo(() => getTargetUrl(), []); + + // If already trusted, redirect immediately + const alreadyTrusted = useMemo( + () => Boolean(targetUrl && isUrlTrusted(targetUrl)), + [targetUrl], + ); + + if (alreadyTrusted && targetUrl) { + window.location.href = targetUrl; Review Comment: ## Client-side URL redirect Untrusted URL redirection depends on a [user-provided value](1). [Show more details](https://github.com/apache/superset/security/code-scanning/2240) ########## superset-frontend/src/pages/RedirectWarning/index.tsx: ########## @@ -0,0 +1,183 @@ +/** + * 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 { useState, useMemo, useCallback } from 'react'; +import { t } from '@superset-ui/core'; +import { css, styled, useTheme } from '@apache-superset/core/ui'; +import { + Button, + Card, + Checkbox, + Flex, + Typography, +} from '@superset-ui/core/components'; +import { Icons } from '@superset-ui/core/components/Icons'; +import { + getTargetUrl, + isUrlTrusted, + trustUrl, + isAllowedScheme, +} from './utils'; + +const PageContainer = styled(Flex)` + ${({ theme }) => css` + height: calc(100vh - 64px); + background-color: ${theme.colorBgLayout}; + padding: ${theme.padding}px; + `} +`; + +const WarningCard = styled(Card)` + ${({ theme }) => css` + max-width: 520px; + width: 100%; + box-shadow: ${theme.boxShadowSecondary}; + `} +`; + +const WarningHeader = styled(Flex)` + ${({ theme }) => css` + padding: ${theme.paddingLG}px ${theme.paddingXL}px; + border-bottom: 1px solid ${theme.colorBorderSecondary}; + `} +`; + +const WarningBody = styled.div` + ${({ theme }) => css` + padding: ${theme.paddingXL}px; + `} +`; + +const UrlDisplay = styled(Flex)` + ${({ theme }) => css` + background-color: ${theme.colorFillQuaternary}; + border-radius: ${theme.borderRadiusSM}px; + padding: ${theme.paddingSM}px ${theme.padding}px; + margin-bottom: ${theme.margin}px; + `} +`; + +const UrlText = styled(Typography.Text)` + ${({ theme }) => css` + font-family: ${theme.fontFamilyCode}; + font-size: ${theme.fontSize}px; + word-break: break-all; + `} +`; + +const WarningFooter = styled(Flex)` + ${({ theme }) => css` + padding: ${theme.padding}px ${theme.paddingXL}px; + background-color: ${theme.colorFillAlter}; + border-top: 1px solid ${theme.colorBorderSecondary}; + `} +`; + +const WarningTitle = styled(Typography.Title)` + && { + margin: 0; + } +`; + +export default function RedirectWarning() { + const theme = useTheme(); + const [trustChecked, setTrustChecked] = useState(false); + + const targetUrl = useMemo(() => getTargetUrl(), []); + + // If already trusted, redirect immediately + const alreadyTrusted = useMemo( + () => Boolean(targetUrl && isUrlTrusted(targetUrl)), + [targetUrl], + ); + + if (alreadyTrusted && targetUrl) { + window.location.href = targetUrl; Review Comment: ## Client-side cross-site scripting Cross-site scripting vulnerability due to [user-provided value](1). [Show more details](https://github.com/apache/superset/security/code-scanning/2241) -- 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]
