Fix: sanitize URLs before placing them on the page (#488)

This commit is contained in:
Paul Frazee 2023-04-15 09:24:03 -07:00 committed by GitHub
parent a6634ec45d
commit a79dcd3d38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View file

@ -23,6 +23,7 @@ import {router} from '../../../routes'
import {useStores, RootStoreModel} from 'state/index'
import {convertBskyAppUrlIfNeeded} from 'lib/strings/url-helpers'
import {isDesktopWeb} from 'platform/detection'
import {sanitizeUrl} from '@braintree/sanitize-url'
type Event =
| React.MouseEvent<HTMLAnchorElement, MouseEvent>
@ -51,7 +52,7 @@ export const Link = observer(function Link({
const onPress = React.useCallback(
(e?: Event) => {
if (typeof href === 'string') {
return onPressInner(store, navigation, href, e)
return onPressInner(store, navigation, sanitizeUrl(href), e)
}
},
[store, navigation, href],
@ -63,7 +64,7 @@ export const Link = observer(function Link({
testID={testID}
onPress={onPress}
// @ts-ignore web only -prf
href={asAnchor ? href : undefined}>
href={asAnchor ? sanitizeUrl(href) : undefined}>
<View style={style}>
{children ? children : <Text>{title || 'link'}</Text>}
</View>
@ -76,7 +77,7 @@ export const Link = observer(function Link({
style={style}
onPress={onPress}
// @ts-ignore web only -prf
href={asAnchor ? href : undefined}>
href={asAnchor ? sanitizeUrl(href) : undefined}>
{children ? children : <Text>{title || 'link'}</Text>}
</TouchableOpacity>
)
@ -101,13 +102,13 @@ export const TextLink = observer(function TextLink({
lineHeight?: number
dataSet?: any
}) {
const {...props} = useLinkProps({to: href})
const {...props} = useLinkProps({to: sanitizeUrl(href)})
const store = useStores()
const navigation = useNavigation<NavigationProp>()
props.onPress = React.useCallback(
(e?: Event) => {
return onPressInner(store, navigation, href, e)
return onPressInner(store, navigation, sanitizeUrl(href), e)
},
[store, navigation, href],
)