Issues (61)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

js/upload-helper.js (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
/* global Gallery, Thumbnails */
2
/**
3
 * OCA.FileList methods needed for file uploading
4
 *
5
 * This hack makes it possible to use the Files scripts as is, without having to import and
6
 * maintain them in Gallery
7
 *
8
 * Empty methods are for the "new" button, if we want to implement that one day
9
 *
10
 * @type {{inList: FileList.inList, lastAction: FileList.lastAction, getUniqueName:
11
 *     FileList.getUniqueName, getCurrentDirectory: FileList.getCurrentDirectory, add:
12
 *     FileList.add, checkName: FileList.checkName}}
13
 */
14
var FileList = {
0 ignored issues
show
Redefinition of 'FileList'.
Loading history...
15
	/**
16
	 * Makes sure the filename does not exist
17
	 *
18
	 * Gives an early chance to the user to abort the action, before uploading everything to the
19
	 * server.
20
	 * Albums are not supported as we don't have a full list of images contained in a sub-album
21
	 *
22
	 * @param fileName
23
	 * @returns {*}
24
	 */
25
	findFile: function (fileName) {
26
		"use strict";
27
		var path = Gallery.currentAlbum + '/' + fileName;
28
		var galleryImage = Gallery.imageMap[path];
29
		if (galleryImage) {
30
			var fileInfo = {
31
				name: fileName,
32
				directory: Gallery.currentAlbum,
33
				path: path,
34
				etag: galleryImage.etag,
35
				mtime: galleryImage.mTime * 1000, // Javascript gives the Epoch time in milliseconds
36
				size: galleryImage.size
37
			};
38
			return fileInfo;
39
		} else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
40
			return null;
41
		}
42
	},
43
44
	/**
45
	 * Refreshes the photowall
46
	 *
47
	 * Called at the end of the uploading process when 1 or multiple files are sent
48
	 * Never called with folders on Chrome, unless files are uploaded at the same time as folders
49
	 *
50
	 * @param fileList
51
	 */
52
	highlightFiles: function (fileList) {
53
		"use strict";
54
		//Ask for a refresh of the photowall
55
		Gallery.getFiles(Gallery.currentAlbum).done(function () {
56
			var fileId, path;
57
			// Removes the cached thumbnails of files which have been re-uploaded
58
			_(fileList).each(function (fileName) {
59
				path = Gallery.currentAlbum + '/' + fileName;
60
				if (Gallery.imageMap[path]) {
61
					fileId = Gallery.imageMap[path].fileId;
62
					if (Thumbnails.map[fileId]) {
63
						delete Thumbnails.map[fileId];
64
					}
65
				}
66
			});
67
68
			Gallery.view.init(Gallery.currentAlbum);
69
		});
70
	},
71
72
	/**
73
	 * Create an empty file inside the current album.
74
	 *
75
	 * @param {string} name name of the file
76
	 *
77
	 * @return {Promise} promise that will be resolved after the
78
	 * file was created
79
	 *
80
	 */
81
	createFile: function(name) {
82
		var self = this;
83
		var deferred = $.Deferred();
84
		var promise = deferred.promise();
85
86
		OCA.Files.isFileNameValid(name);
87
88
		var targetPath = this.getCurrentDirectory() + '/' + name;
89
90
		//Check if file already exists
91
		if(Gallery.imageMap[targetPath]) {
92
			OC.Notification.showTemporary(
93
				t('files', 'Could not create file "{file}" because it already exists', {file: name})
94
			);
95
			deferred.reject();
96
			return promise;
97
		}
98
99
		Gallery.filesClient.putFileContents(
100
			targetPath,
101
			'',
102
			{
103
				contentType: 'text/plain',
104
				overwrite: true
105
			}
106
			)
107
			.done(function() {
108
				// TODO: error handling / conflicts
109
				Gallery.filesClient.getFileInfo(
110
					targetPath, {
111
						properties: self.findFile(targetPath)
112
					}
113
					)
114
					.then(function(status, data) {
115
						deferred.resolve(status, data);
116
					})
117
					.fail(function(status) {
118
						OC.Notification.showTemporary(t('files', 'Could not create file "{file}"', {file: name}));
119
						deferred.reject(status);
120
					});
121
			})
122
			.fail(function(status) {
123
				if (status === 412) {
124
					OC.Notification.showTemporary(
125
						t('files', 'Could not create file "{file}" because it already exists', {file: name})
126
					);
127
				} else {
128
					OC.Notification.showTemporary(t('files', 'Could not create file "{file}"', {file: name}));
129
				}
130
				deferred.reject(status);
131
			});
132
133
		return promise;
134
	},
135
136
137
	/**
138
	 * Retrieves the current album
139
	 *
140
	 * @returns {string}
141
	 */
142
	getCurrentDirectory: function () {
143
		"use strict";
144
145
		// In Files, dirs start with a /
146
		return '/' + Gallery.currentAlbum;
147
	}
148
};
149
150
/**
151
 * OCA.Files methods needed for file uploading
152
 *
153
 * This hack makes it possible to use the Files scripts as is, without having to import and
154
 * maintain them in Gallery
155
 *
156
 * @type {{isFileNameValid: Files.isFileNameValid, generatePreviewUrl: Files.generatePreviewUrl}}
157
 */
158
var Files = {
159
	App: {fileList: {}},
160
161
	isFileNameValid: function (name) {
162
		"use strict";
163
		var trimmedName = name.trim();
164
		if (trimmedName === '.' || trimmedName === '..') {
165
			throw t('files', '"{name}" is an invalid file name.', {name: name});
166
		} else if (trimmedName.length === 0) {
167
			throw t('files', 'File name cannot be empty.');
168
		}
169
		return true;
170
171
	},
172
173
	/**
174
	 * Generates a preview for the conflict dialogue
175
	 *
176
	 * Since Gallery uses the fileId and Files uses the path, we have to use the preview endpoint
177
	 * of Files
178
	 */
179
	generatePreviewUrl: function (urlSpec) {
180
		"use strict";
181
		var previewUrl;
182
		var path = urlSpec.file;
183
184
		// In Files, root files start with //
185
		if (path.indexOf('//') === 0) {
186
			path = path.substring(2);
187
		} else {
188
			// Directories start with /
189
			path = path.substring(1);
190
		}
191
192
		if (Gallery.imageMap[path]) {
193
			var fileId = Gallery.imageMap[path].fileId;
194
			var thumbnail = Thumbnails.map[fileId];
195
			previewUrl = thumbnail.image.src;
196
		} else {
197
			var previewDimension = 96;
198
			urlSpec.x = Math.ceil(previewDimension * window.devicePixelRatio);
199
			urlSpec.y = Math.ceil(previewDimension * window.devicePixelRatio);
200
			urlSpec.forceIcon = 0;
201
			previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec);
202
		}
203
204
		return previewUrl;
205
	}
206
};
207
208
OCA.Files = Files;
209
OCA.Files.App.fileList = FileList;
210