Skip to content

Commit

Permalink
add whitelist mode and fix clipboard glyph
Browse files Browse the repository at this point in the history
  • Loading branch information
nokonoko committed Jul 3, 2021
1 parent 6fb976d commit 5e56fb9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"allowErrors": false
},
"dest": "dist",
"pkgVersion": "1.1.2",
"pkgVersion": "1.2.0",
"banners": [
"banners/malware_scans.swig",
"banners/donations.swig"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uguu",
"version": "1.1.2",
"version": "1.2.0",
"description": "Kawaii file host",
"homepage": "https://uguu.se/",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion static/css/uguu.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ nav > ul > li:last-child:after {
color: #891A18;
}
button.upload-clipboard-btn {
height: 16px;
height: 32px;
}
.error#upload-filelist .progress-percent {
color: #B94A48;
Expand Down
16 changes: 10 additions & 6 deletions static/php/includes/settings.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
/* @param string UGUU_DB_PASS Database password */
define('UGUU_DB_PASS', 'NULL');

/** Log IP of uploads */
/**
* @param boolean Log IP of uploads
*/
define('LOG_IP', false);

/** Dont upload a file already in the DB */
/**
* @param boolean anti-dupe
*/
define('ANTI_DUPE', false);

/*
Expand Down Expand Up @@ -78,11 +82,11 @@
define('CONFIG_BLOCKED_MIME', serialize(['application/msword', 'text/html', 'application/x-dosexec', 'application/java', 'application/java-archive', 'application/x-executable', 'application/x-mach-binary', 'image/svg+xml']));

/**
* Filter mode: whitelist (true) or blacklist (false).
*
* @param bool $FILTER_MODE mime type filter mode
* Whitelist or blacklist mode
* @param boolean blacklist (false) | whitelist (true)
*/
$FILTER_MODE = false;
define('CONFIG_FILTER_MODE', false);

/**
* Double dot file extensions.
*
Expand Down
39 changes: 28 additions & 11 deletions static/php/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,34 @@ function generateName($file)
$name .= '.'.$ext;
}

//Check if MIME is blacklisted
if (in_array($type_mime, unserialize(CONFIG_BLOCKED_MIME))) {
http_response_code(415);
exit(0);
}
//Check if EXT is blacklisted
if (in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))) {
http_response_code(415);
exit(0);
// Check if file is whitelisted or blacklisted
switch (CONFIG_FILTER_MODE) {

case false:
//check if MIME is blacklisted
if (in_array($type_mime, unserialize(CONFIG_BLOCKED_MIME))) {
http_response_code(415);
exit(0);
}
//Check if EXT is blacklisted
if (in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))) {
http_response_code(415);
exit(0);
}
break;

case true:
//Check if MIME is whitelisted
if (!in_array($type_mime, unserialize(CONFIG_BLOCKED_MIME))) {
http_response_code(415);
exit(0);
}
//Check if EXT is whitelisted
if (!in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))) {
http_response_code(415);
exit(0);
}
break;
}

// Check if a file with the same name does already exist in the database
Expand All @@ -93,8 +112,6 @@ function generateName($file)
function uploadFile($file)
{
global $db;
global $FILTER_MODE;
global $FILTER_MIME;

// Handle file errors
if ($file->error) {
Expand Down

0 comments on commit 5e56fb9

Please sign in to comment.