mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 18:40:00 +08:00
feat: drop outdated session (#14373)
#### PR Dependency Tree * **PR #14373** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added client version tracking and validation to ensure application compatibility across authentication flows and sessions. * Enhanced OAuth authentication with improved version handling during sign-in and refresh operations. * **Bug Fixes** * Improved payment callback URL handling with safer defaults for redirect links. * **Tests** * Expanded test coverage for client version enforcement and session management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export * from './duration';
|
||||
export * from './promise';
|
||||
export * from './request';
|
||||
export * from './request-tracker';
|
||||
export * from './ssrf';
|
||||
export * from './stream';
|
||||
export * from './types';
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { Request } from 'express';
|
||||
|
||||
function firstForwardedForIp(value?: string) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [first] = value.split(',', 1);
|
||||
const ip = first?.trim();
|
||||
|
||||
return ip || undefined;
|
||||
}
|
||||
|
||||
function firstNonEmpty(...values: Array<string | undefined>) {
|
||||
for (const value of values) {
|
||||
const trimmed = value?.trim();
|
||||
if (trimmed) {
|
||||
return trimmed;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
export function getRequestClientIp(req: Request) {
|
||||
return firstNonEmpty(
|
||||
req.get('CF-Connecting-IP'),
|
||||
firstForwardedForIp(req.get('X-Forwarded-For')),
|
||||
req.get('X-Real-IP'),
|
||||
req.ip
|
||||
)!;
|
||||
}
|
||||
|
||||
export function getRequestTrackerId(req: Request) {
|
||||
return (
|
||||
req.session?.sessionId ??
|
||||
firstNonEmpty(
|
||||
req.get('CF-Connecting-IP'),
|
||||
firstForwardedForIp(req.get('X-Forwarded-For')),
|
||||
req.get('X-Real-IP'),
|
||||
req.get('CF-Ray'),
|
||||
req.ip
|
||||
)!
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user