slight mods to open redirect fix

This commit is contained in:
keyan 2023-05-07 08:33:51 -05:00
parent a396933be2
commit 8830b8ee9c
3 changed files with 10 additions and 8 deletions

View File

@ -5,6 +5,10 @@ export function ensureProtocol (value) {
return value
}
export function isExternal (url) {
return !url.startsWith(process.env.PUBLIC_URL) && !url.startsWith('/')
}
export function removeTracking (value) {
const exprs = [
// twitter URLs

View File

@ -2,16 +2,15 @@ import { providers, getSession } from 'next-auth/client'
import Link from 'next/link'
import LayoutStatic from '../components/layout-static'
import Login from '../components/login'
import { isExternal } from '../lib/url'
export async function getServerSideProps ({ req, res, query: { callbackUrl, error = null } }) {
const session = await getSession({ req })
const regex = /^https?:\/\/stacker.news\//
const external = !regex.test(decodeURIComponent(callbackUrl))
const external = isExternal(decodeURIComponent(callbackUrl))
if (external) {
// This is a hotfix for open redirects. See https://github.com/stackernews/stacker.news/issues/264
// TODO: Add redirect notice to warn users
return res.status(500).end()
callbackUrl = '/'
}
if (session && res && callbackUrl) {

View File

@ -2,16 +2,15 @@ import { providers, getSession } from 'next-auth/client'
import Link from 'next/link'
import LayoutStatic from '../components/layout-static'
import Login from '../components/login'
import { isExternal } from '../lib/url'
export async function getServerSideProps ({ req, res, query: { callbackUrl, error = null } }) {
const session = await getSession({ req })
const regex = /^https?:\/\/stacker.news\//
const external = !regex.test(decodeURIComponent(callbackUrl))
const external = isExternal(decodeURIComponent(callbackUrl))
if (external) {
// This is a hotfix for open redirects. See https://github.com/stackernews/stacker.news/issues/264
// TODO: Add redirect notice to warn users
return res.status(500).end()
callbackUrl = '/'
}
if (session && res && callbackUrl) {