fix(wx): strip identity from share page_path; guard router unionid switch
- Sanitize page_path before router.push (H5) to prevent cross-user login via shared link - onShareAppMessage: remove unionid/openid/status and related query keys from shared path - main.ts: fix login(to.query.toString()) bug; when already logged in, strip foreign unionid from URL instead of logout Made-with: Cursor
This commit is contained in:
@@ -211,8 +211,29 @@ Page({
|
||||
onShareAppMessage({from, target, webViewUrl}) {
|
||||
log.info("share", [from, target, webViewUrl].join(" | "))
|
||||
let pathname = webViewUrl.replace(app.globalData.server, '');
|
||||
if (pathname !== '/') {
|
||||
pathname = encodeURIComponent(pathname)
|
||||
// 分享勿带 WebView 入口里的 unionid/openid/status 等,避免接收方串号
|
||||
if (pathname && pathname !== '/') {
|
||||
try {
|
||||
const q = pathname.indexOf('?')
|
||||
let base = pathname
|
||||
let search = ''
|
||||
if (q === 0) {
|
||||
base = '/'
|
||||
search = pathname.slice(1)
|
||||
} else if (q > 0) {
|
||||
base = pathname.slice(0, q) || '/'
|
||||
search = pathname.slice(q + 1)
|
||||
}
|
||||
if (search) {
|
||||
const sp = new URLSearchParams(search)
|
||||
;['unionid', 'openid', 'status', 'nickName', 'avatarUrl', 'ts', 'scene'].forEach((k) => sp.delete(k))
|
||||
const rest = sp.toString()
|
||||
pathname = rest ? `${base}?${rest}` : (base || '/')
|
||||
}
|
||||
} catch (e) {
|
||||
log.info('share strip query skip', e)
|
||||
}
|
||||
pathname = pathname === '/' ? '/' : encodeURIComponent(pathname)
|
||||
}
|
||||
const promise = new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user