@@ -124,15 +124,16 @@ def list_directory(self, path):
124124 linkname = urllib .parse .quote (linkname )
125125 displayname = html .escape (displayname )
126126
127- # TODO: Handle insertion of JS links
127+ # Handle insertion of JS links
128128 if self .B64_ENCODE_PAYLOAD :
129+
129130 # implenet call to JS via onClick
130-
131131 f .write (
132- '<li><a href="javascript:decoder(\' {}\' )">{}</a>\n ' .format (
133- linkname ,
134- linkname ,
135- displayname ).encode ('utf8' )
132+ self .B64_LINK .format (
133+ linkname ,
134+ linkname ,
135+ displayname
136+ ).encode ('utf8' )
136137 )
137138
138139 else :
@@ -158,6 +159,11 @@ class CorsHandler(http.server.SimpleHTTPRequestHandler):
158159
159160 B64_ENCODE_PAYLOAD = False
160161 B64_JS_TEMPLATE = None
162+ B64_LINK = None
163+ B64_LINK_TEMPLATE = \
164+ '<li><a href="javascript:downloader(\' {}\' ,true)">{}</a>\n '
165+ B64_NO_DECODE_LINK_TEMPLATE = \
166+ '<li><a href="javascript:downloader(\' {}\' ,false)">{}</a>\n '
161167
162168 @property
163169 def client_ip (self ):
@@ -473,7 +479,7 @@ def do_basic_POST(self):
473479
474480def run_server (interface , port , keyfile , certfile ,
475481 webroot = None , enable_uploads = False , enable_b64 = False ,
476- * args , ** kwargs ):
482+ disable_browser_decode = False , * args , ** kwargs ):
477483
478484 # ============================
479485 # CONFIGURE BASE64 OBFUSCATION
@@ -488,6 +494,12 @@ def run_server(interface, port, keyfile, certfile,
488494 '/templates/b64_obfuscation.js' ,'r' ) as infile :
489495 CorsHandler .B64_JS_TEMPLATE = infile .read ()
490496
497+ # Select proper link template based on supplied options
498+ if disable_browser_decode :
499+ CorsHandler .B64_LINK = CorsHandler .B64_NO_DECODE_LINK_TEMPLATE
500+ else :
501+ CorsHandler .B64_LINK = CorsHandler .B64_LINK_TEMPLATE
502+
491503 webroot = webroot or '.'
492504
493505 # Update CorsHandler with upload functionality
@@ -633,8 +645,23 @@ def generate_certificate(certfile, keyfile):
633645 obf_group .add_argument ('--enable-b64' ,
634646 help = 'Enable double base 64 obfuscation of files.' ,
635647 action = 'store_true' )
648+ obf_group .add_argument ('--disable-browser-decode' ,
649+ help = 'Disable decoding at the browser. This may be disirable '
650+ 'in situations where browser developers don\' t give a damn ab'
651+ 'out your privacy and upload your downloaded files to scanner'
652+ 's.' ,
653+ action = 'store_true' )
636654
637655 args = parser .parse_args ()
656+
657+
658+ if not args .enable_b64 and args .disable_browser_decode :
659+
660+ spring ('Warning: Browser decoding has been disabled but '
661+ 'Base64 encoding has not been enabled. Configuration ign'
662+ 'ored.' )
663+
664+ args .disable_browser_decode = False
638665
639666 # handle basic auth credentials
640667 if args .basic_username and not args .basic_password or (
0 commit comments