Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Ask for authentication
if (this.hooks.authentication) {
if (!req.headers.authorization) {
debug('%s:%s - No authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
res.statusCode = 401;
return false;
} else {
if (req.headers.session && this.clients[req.headers.session] && this.clients[req.headers.session].authorizationHeader !== req.headers.authorization) {
debug('%s:%s - session header doesn\'t match the cached value, sending 401', req.socket.remoteAddress, req.socket.remotePort);
res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
res.statusCode = 401;
return false;
}
const result = parse(req.headers.authorization);
if (!result) {
debug('%s:%s - No authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
res.statusCode = 401;
return false;
}
const allowed = await this.hooks.authentication(result.name, result.pass, req, res);
if (!allowed) {
debug('%s:%s - No authentication information (hook returned false), sending 401', req.socket.remoteAddress, req.socket.remotePort);
res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
res.statusCode = 401;
return false;
}
}
}
async putUndeployResult(
@Req() request: Express.Request,
@Res() response: Express.Response,
@HeaderParams("Authorization") auth: string,
@BodyParams("") body: any,
): Promise {
const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);
let cluster;
try {
cluster = await (request.app.locals.stores.clusterStore as ClusterStore).getFromDeployToken(credentials.pass);
} catch (err) {
// TODO error type
response.status(401);
return {};
}
const status = body.is_error ? UndeployStatus.Failed : UndeployStatus.Completed;
logger.info(`Restore API set RestoreUndeployStatus = ${status} for app ${body.app_id}`);
const kotsAppStore = request.app.locals.stores.kotsAppStore as KotsAppStore;
const app = await kotsAppStore.getApp(body.app_id);
if (app.restoreInProgressName) {
// Add a delay until we have logic to wait for all pods to be deleted.
async announceRequest (req: RtspRequest, res: RtspResponse) {
debug('%s:%s - Announce request with headers %o', req.socket.remoteAddress, req.socket.remotePort, req.headers);
// Ask for authentication
if (this.hooks.authentication) {
if (!req.headers.authorization) {
debug('%s:%s - No authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
res.statusCode = 401;
return res.end();
} else {
const result = parse(req.headers.authorization);
if (!result) {
debug('%s:%s - Invalid authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
res.statusCode = 401;
return res.end();
}
const allowed = await this.hooks.authentication(result.name, result.pass, req, res);
if (!allowed) {
debug('%s:%s - Invalid authentication information (Hook returned false), sending 401', req.socket.remoteAddress, req.socket.remotePort);
res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
res.statusCode = 401;
return res.end();
}
this.authenticatedHeader = req.headers.authorization;
async putDeployResult(
@Req() request: Express.Request,
@Res() response: Express.Response,
@HeaderParams("Authorization") auth: string,
@BodyParams("") body: any,
): Promise {
const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);
let cluster;
try {
cluster = await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
} catch (err) {
// TODO error type
response.status(401);
return {};
}
const output = {
dryRun: {
stderr: body.dryrun_stderr,
stdout: body.dryrun_stdout,
},
apply: {
async putAppStatus(
@Req() request: Express.Request,
@Res() response: Express.Response,
@HeaderParams("Authorization") auth: string,
@BodyParams("") body: any,
): Promise {
const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);
try {
await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
} catch (err) {
// TODO error type
response.status(401);
return;
}
const kotsAppStatusStore: KotsAppStatusStore = request.app.locals.stores.kotsAppStatusStore;
await kotsAppStatusStore.setKotsAppStatus(body.app_id, body.resource_states, body.updated_at);
response.status(204);
}
}
async getDesiredState(
@Req() request: Express.Request,
@Res() response: Express.Response,
@HeaderParams("Authorization") auth: string,
): Promise {
const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);
let cluster;
try {
cluster = await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
} catch (err) {
// TODO error type
response.status(401);
return {};
}
try {
const apps = await request.app.locals.stores.kotsAppStore.listAppsForCluster(cluster.id);
const present: any[] = [];
const missing = {};
let preflight = [];
testProxyServer.on('proxyRes', function (proxyRes, req, res, options) {
if (req.url == getTestURL('/proxyAuthenticate')){
var user = auth.parse(req.headers['proxy-authorization']);
if (!(user.name == "foouser" && user.pass == "barpassword")){
proxyRes.headers['proxy-authenticate'] = 'BASIC realm="test"';
proxyRes.statusCode = 407;
}
}
});
testProxyServer.listen(testProxyPort);
async check () {
if (this.user) {
return true
}
const authString = this._ctx.request.header('authorization') || this._ctx.request.input('basic')
const credentials = auth.parse(authString)
if (!credentials) {
throw CE.InvalidBasicAuthException.invoke()
}
this.user = await this.validate(credentials.name, credentials.pass, true)
return !!this.user
}