Skip to content

Commit 585326e

Browse files
author
Peter Palfrader
committedApr 8, 2021
Create a unique temp file
lektor-i18n-plugin used the file /tmp/templates.pot in its workings. (Where /tmp/ could be something else as returned by tempfile.gettempdir()). Using a fixed name for a "temporary" file in a directory that is writable by other users is a security issue. Further, using the same file in multiple (parallel) runs of lektor may lead to undesired results. Hence, we now use a proper tempfile as created by tempfile.NamedTemporaryFile().
1 parent 0fb9563 commit 585326e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎lektor_i18n.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,18 @@ def on_after_build(self, builder, build_state, source, prog, **extra):
426426
self.process_node(fields, sections, source, source.datamodel.id, builder.env.root_path)
427427

428428

429+
def get_templates_pot_filename(self):
430+
try:
431+
return self.pot_templates_filename
432+
except AttributeError:
433+
self.pot_templates_file = tempfile.NamedTemporaryFile(suffix=".pot",prefix="templates-")
434+
self.pot_templates_filename = self.pot_templates_file.name
435+
return self.pot_templates_filename
436+
429437
def on_before_build_all(self, builder, **extra):
430438
if self.enabled:
431439
reporter.report_generic("i18n activated, with main language %s"% self.content_language )
432-
templates_pot_filename = join(tempfile.gettempdir(), 'templates.pot')
440+
templates_pot_filename = self.get_templates_pot_filename()
433441
reporter.report_generic("Parsing templates for i18n into %s" \
434442
% relpath(templates_pot_filename, builder.env.root_path))
435443
translations.parse_templates(templates_pot_filename)
@@ -443,7 +451,7 @@ def on_after_build_all(self, builder, **extra):
443451
return
444452
contents_pot_filename = join(builder.env.root_path, self.i18npath, 'contents.pot')
445453
pots = [contents_pot_filename,
446-
join(tempfile.gettempdir(), 'templates.pot'),
454+
self.get_templates_pot_filename(),
447455
join(builder.env.root_path, self.i18npath, 'plugins.pot')]
448456
# write out contents.pot from web site contents
449457
translations.write_pot(pots[0], self.content_language)
@@ -458,5 +466,3 @@ def on_after_build_all(self, builder, **extra):
458466
for language in self.translations_languages:
459467
po_file=POFile(language, self.i18npath)
460468
po_file.generate()
461-
462-

0 commit comments

Comments
 (0)
Please sign in to comment.