mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
Merge branch 'master' of github.com:fish-shell/fish-shell
This commit is contained in:
commit
2da435712a
1 changed files with 12 additions and 4 deletions
|
@ -26,7 +26,7 @@ if term:
|
||||||
os.environ['TERM'] = term
|
os.environ['TERM'] = term
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import re, socket, cgi, select, time, glob, random, string
|
import re, socket, cgi, select, time, glob, random, string, binascii
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -680,6 +680,14 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
result.extend([r for r in sample_results if r])
|
result.extend([r for r in sample_results if r])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def secure_startswith(self, haystack, needle):
|
||||||
|
if len(haystack) < len(needle):
|
||||||
|
return False
|
||||||
|
bits = 0
|
||||||
|
for x,y in zip(haystack, needle):
|
||||||
|
bits |= ord(x) ^ ord(y)
|
||||||
|
return bits == 0
|
||||||
|
|
||||||
def font_size_for_ansi_prompt(self, prompt_demo_ansi):
|
def font_size_for_ansi_prompt(self, prompt_demo_ansi):
|
||||||
width = ansi_prompt_line_width(prompt_demo_ansi)
|
width = ansi_prompt_line_width(prompt_demo_ansi)
|
||||||
# Pick a font size
|
# Pick a font size
|
||||||
|
@ -697,7 +705,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
p = self.path
|
p = self.path
|
||||||
|
|
||||||
authpath = '/' + authkey
|
authpath = '/' + authkey
|
||||||
if p.startswith(authpath):
|
if self.secure_startswith(p, authpath):
|
||||||
p = p[len(authpath):]
|
p = p[len(authpath):]
|
||||||
else:
|
else:
|
||||||
return self.send_error(403)
|
return self.send_error(403)
|
||||||
|
@ -736,7 +744,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
p = self.path
|
p = self.path
|
||||||
|
|
||||||
authpath = '/' + authkey
|
authpath = '/' + authkey
|
||||||
if p.startswith(authpath):
|
if self.secure_startswith(p, authpath):
|
||||||
p = p[len(authpath):]
|
p = p[len(authpath):]
|
||||||
else:
|
else:
|
||||||
return self.send_error(403)
|
return self.send_error(403)
|
||||||
|
@ -851,7 +859,7 @@ where = os.path.dirname(sys.argv[0])
|
||||||
os.chdir(where)
|
os.chdir(where)
|
||||||
|
|
||||||
# Generate a 16-byte random key as a hexadecimal string
|
# Generate a 16-byte random key as a hexadecimal string
|
||||||
authkey = hex(random.getrandbits(16*4))[2:]
|
authkey = binascii.b2a_hex(os.urandom(16))
|
||||||
|
|
||||||
# Try to find a suitable port
|
# Try to find a suitable port
|
||||||
PORT = 8000
|
PORT = 8000
|
||||||
|
|
Loading…
Reference in a new issue