Browse Source

Validate stdout paths

This should prevent breaking out of the search to grep /etc/shadow or similar shenanigans.
master
JustAnotherArchivist 3 years ago
parent
commit
26aea9d827
1 changed files with 3 additions and 1 deletions
  1. +3
    -1
      irclog.py

+ 3
- 1
irclog.py View File

@@ -877,12 +877,14 @@ class WebServer:
yield (path, line)

def _stdout_with_path(self, stdout):
# Process grep output with --with-filenames, --null, and --line-number into (path, line) tuples; this blindly assumes the expected directory structure of '.../path/YYYY-MM.log'.
# Process grep output with --with-filenames, --null, and --line-number into (path, line) tuples.
# Lines are sorted by timestamp, filename, and line number to ensure a consistent and chronological order.
out = []
for line in stdout.decode('utf-8').splitlines():
fn, line = line.split('\0', 1)
assert fn.startswith(self.config['storage']['path'] + '/') and fn.count('/', len(self.config['storage']['path']) + 1) == 1
_, path, _ = fn.rsplit('/', 2)
assert path in self._paths
ln, line = line.split(':', 1)
ln = int(ln)
ts = float(line.split(' ', 1)[0])


Loading…
Cancel
Save