Skip to content

Commit

Permalink
Fixes #1054 - Relax limitation on special chars for --add-header key …
Browse files Browse the repository at this point in the history
…names

We are too restrictive on the list of characters that are allowed to be
used in "header name" for the --add-headers option.

The http specification a larger set of characters for header names.
Adding the following ones: !#$%&*+^_|
Still, even if no issue is to be expected, I would not advice anyone to
use any of these chars for a header name.
  • Loading branch information
fviard committed Mar 26, 2020
1 parent 92df370 commit c8de951
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion S3/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def read_config_file(self, configfile):
if cp.get('add_headers'):
for option in cp.get('add_headers').split(","):
(key, value) = option.split(':')
self.extra_headers[key.replace('_', '-').strip()] = value.strip()
self.extra_headers[key.strip()] = value.strip()

self._parsed_files.append(configfile)

Expand Down
11 changes: 7 additions & 4 deletions s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2835,13 +2835,16 @@ def main():
key, val = unicodise_s(hdr).split(":", 1)
except ValueError:
raise ParameterError("Invalid header format: %s" % unicodise_s(hdr))
key_inval = re.sub("[a-zA-Z0-9-.]", "", key)
# key char restrictions of the http headers name specification
key_inval = re.sub(r"[a-zA-Z0-9\-.!#$%&*+^_|]", "", key)
if key_inval:
key_inval = key_inval.replace(" ", "<space>")
key_inval = key_inval.replace("\t", "<tab>")
raise ParameterError("Invalid character(s) in header name '%s': \"%s\"" % (key, key_inval))
debug(u"Updating Config.Config extra_headers[%s] -> %s" % (key.replace('_', '-').strip().lower(), val.strip()))
cfg.extra_headers[key.replace('_', '-').strip().lower()] = val.strip()
raise ParameterError("Invalid character(s) in header name '%s'"
": \"%s\"" % (key, key_inval))
debug(u"Updating Config.Config extra_headers[%s] -> %s" %
(key.strip().lower(), val.strip()))
cfg.extra_headers[key.strip().lower()] = val.strip()

# Process --remove-header
if options.remove_headers:
Expand Down

0 comments on commit c8de951

Please sign in to comment.