bypass localhost / route

This commit is contained in:
Peter Steinberger 2025-06-24 03:46:16 +02:00
parent 17cffe7424
commit ef9a757608
2 changed files with 12 additions and 1 deletions

View file

@ -10,6 +10,7 @@ interface AuthRoutesConfig {
enableSSHKeys?: boolean; enableSSHKeys?: boolean;
disallowUserPassword?: boolean; disallowUserPassword?: boolean;
noAuth?: boolean; noAuth?: boolean;
allowLocalBypass?: boolean;
} }
export function createAuthRoutes(config: AuthRoutesConfig): Router { export function createAuthRoutes(config: AuthRoutesConfig): Router {
@ -174,10 +175,19 @@ export function createAuthRoutes(config: AuthRoutesConfig): Router {
*/ */
router.get('/config', (req, res) => { router.get('/config', (req, res) => {
try { try {
// Check if this is a local request and local bypass is enabled
const clientIp = req.ip || req.socket.remoteAddress || '';
const localIPs = ['127.0.0.1', '::1', '::ffff:127.0.0.1', 'localhost'];
const isLocalRequest =
localIPs.includes(clientIp) && !req.headers['x-forwarded-for'] && !req.headers['x-real-ip'];
// If local bypass is enabled and this is a local request, report as noAuth
const effectiveNoAuth = config.noAuth || (config.allowLocalBypass && isLocalRequest);
res.json({ res.json({
enableSSHKeys: config.enableSSHKeys || false, enableSSHKeys: config.enableSSHKeys || false,
disallowUserPassword: config.disallowUserPassword || false, disallowUserPassword: config.disallowUserPassword || false,
noAuth: config.noAuth || false, noAuth: effectiveNoAuth,
}); });
} catch (error) { } catch (error) {
console.error('Error getting auth config:', error); console.error('Error getting auth config:', error);

View file

@ -479,6 +479,7 @@ export async function createApp(): Promise<AppInstance> {
enableSSHKeys: config.enableSSHKeys, enableSSHKeys: config.enableSSHKeys,
disallowUserPassword: config.disallowUserPassword, disallowUserPassword: config.disallowUserPassword,
noAuth: config.noAuth, noAuth: config.noAuth,
allowLocalBypass: config.allowLocalBypass,
}) })
); );
logger.debug('Mounted authentication routes'); logger.debug('Mounted authentication routes');