<commit_before>/* globals FileUpload, WebApp, Cookies */
var protectedFiles;

RocketChat.settings.get('FileUpload_ProtectFiles', function(key, value) {
	protectedFiles = value;
});

WebApp.connectHandlers.use('/file-upload/', function(req, res, next) {
	var file;

	var match = /^\/([^\/]+)\/(.*)/.exec(req.url);

	if (match[1]) {
		file = RocketChat.models.Uploads.findOneById(match[1]);

		if (file) {
			if (protectedFiles) {
				var cookie, rawCookies, ref, token, uid;
				cookie = new Cookies();

				if ((typeof req !== 'undefined' && req !== null ? (ref = req.headers) != null ? ref.cookie : void 0 : void 0) != null) {
					rawCookies = req.headers.cookie;
				}

				if (rawCookies != null) {
					uid = cookie.get('rc_uid', rawCookies);
				}

				if (rawCookies != null) {
					token = cookie.get('rc_token', rawCookies);
				}

				if (uid == null) {
					uid = req.query.rc_uid;
					token = req.query.rc_token;
				}

				if (!(uid && token && RocketChat.models.Users.findOneByIdAndLoginToken(uid, token))) {
					res.writeHead(403);<commit_msg>Do not protect upload files on Sandstorm environment<commit_after>/* globals FileUpload, WebApp, Cookies */
var protectedFiles;

RocketChat.settings.get('FileUpload_ProtectFiles', function(key, value) {
	protectedFiles = value;
});

WebApp.connectHandlers.use('/file-upload/', function(req, res, next) {
	var file;

	var match = /^\/([^\/]+)\/(.*)/.exec(req.url);

	if (match[1]) {
		file = RocketChat.models.Uploads.findOneById(match[1]);

		if (file) {
			if (!Meteor.settings.public.sandstorm && protectedFiles) {
				var cookie, rawCookies, ref, token, uid;
				cookie = new Cookies();

				if ((typeof req !== 'undefined' && req !== null ? (ref = req.headers) != null ? ref.cookie : void 0 : void 0) != null) {
					rawCookies = req.headers.cookie;
				}

				if (rawCookies != null) {
					uid = cookie.get('rc_uid', rawCookies);
				}

				if (rawCookies != null) {
					token = cookie.get('rc_token', rawCookies);
				}

				if (uid == null) {
					uid = req.query.rc_uid;
					token = req.query.rc_token;
				}

				if (!(uid && token && RocketChat.models.Users.findOneByIdAndLoginToken(uid, token))) {
					res.writeHead(403);
{'fraction_non_alphanumeric': 0.17486338797814208, 'fraction_numerical': 0.006375227686703097, 'mean_word_length': 3.266019417475728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5391737', 'n_tokens_mistral': 911, 'n_tokens_neox': 746, 'n_words': 167}