Skip to content

Commit

Permalink
mod_s3_upload: use a more random prefix
Browse files Browse the repository at this point in the history
This makes it significantly more difficult to enumerate the uploaded files. In addition, putting files in smaller folders mitigates S3 issues related to having too many files in a single folder.
  • Loading branch information
mjohnson9 committed Jun 29, 2023
1 parent c455232 commit 88229e9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mod_s3_upload/src/mod_s3_upload.erl
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ object_url(BucketURL, ObjectName) ->
ObjectName :: binary().
% generate reasonably unique sortable (by time first) object name.
object_name(Filename) ->
str:format("~.36B~.36B-~s", [os:system_time(microsecond),
erlang:phash2(node()),
uri_string:quote(Filename)]).
<<RandomPrefix:128/big-unsigned-integer>> = crypto:strong_rand_bytes(16),
RandomPrefixS = str:format("~32.16.0b", [RandomPrefix]),
FolderName = str:substr(RandomPrefixS, 1, 2),
str:format("~s/~s-~s", [FolderName,
RandomPrefixS,
uri_string:quote(Filename)]).

0 comments on commit 88229e9

Please sign in to comment.