+18
-1
packages/appview/src/api/oauth.ts
+18
-1
packages/appview/src/api/oauth.ts
···
51
51
router.post('/oauth/initiate', async (req, res) => {
52
52
// Validate
53
53
const handle = req.body?.handle
54
-
if (typeof handle !== 'string' || !isValidHandle(handle)) {
54
+
if (
55
+
typeof handle !== 'string' ||
56
+
!(isValidHandle(handle) || isValidUrl(handle))
57
+
) {
55
58
res.status(400).json({ error: 'Invalid handle' })
56
59
return
57
60
}
···
81
84
82
85
return router
83
86
}
87
+
88
+
function isValidUrl(url: string): boolean {
89
+
try {
90
+
const urlp = new URL(url)
91
+
// http or https, no query params or path
92
+
return (
93
+
(urlp.protocol === 'http:' || urlp.protocol === 'https:') &&
94
+
!urlp.search &&
95
+
!urlp.pathname
96
+
)
97
+
} catch (error) {
98
+
return false
99
+
}
100
+
}