aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sisudoc/ocda/abstraction
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2026-09-20 23:37:45 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2026-09-22 12:02:31 -0400
commit0e60ccbeeeb6848d571c4caa78850022a9487288 (patch)
tree37fd65af6e71f6dad4527f761336316cca641cf7 /src/sisudoc/ocda/abstraction
parentmarkup: keep a utf-8 bom out of the yaml header (diff)
ocda db: before writing check carried file names
bugfix: content image names are now checked in a pass of their own, before anything is created or written, and one bad name refuses every image in the artefact rather than skipping the one, which is what the zip reader does with a zip. The write then re-checks containment. (prior to this an image name read out of a .ocda.db was written without checks, and such a database can be fetched over https. A name could climb with "..", and being handed to chainPath an absolute name dropped everything before it, so "/x" did not land under the image directory at all. The zip reader has guarded against this since it was written; the database reader did not). carried_names.d holds both rules: a bare filename, as an image is carried, and a relative path, for the markup and conf a database is to carry. (assisted by Claude-Code)
Diffstat (limited to 'src/sisudoc/ocda/abstraction')
-rw-r--r--src/sisudoc/ocda/abstraction/doc_from_artefact.d32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/sisudoc/ocda/abstraction/doc_from_artefact.d b/src/sisudoc/ocda/abstraction/doc_from_artefact.d
index 3a32d25..7cbc73a 100644
--- a/src/sisudoc/ocda/abstraction/doc_from_artefact.d
+++ b/src/sisudoc/ocda/abstraction/doc_from_artefact.d
@@ -86,6 +86,7 @@ template spineDocFromArtefact() {
import sisudoc.ocda.meta.conf_make_meta_structs;
import sisudoc.ocda.meta.doc_matters;
import sisudoc.ocda.io_in.paths_source;
+ import sisudoc.ocda.io_in.carried_names;
import sisudoc.ocda.abstraction.doc_has;
import sisudoc.ocda.abstraction.load;
import sisudoc.ocda.meta.topic_register;
@@ -93,6 +94,7 @@ template spineDocFromArtefact() {
mixin spineDocHasFromAbstraction;
mixin spineAbstractionLoad;
mixin spineTopicRegister;
+ mixin spineCarriedNames;
/+ ↓ a .ssp header key from a field name: the first underscore becomes the
dot that separates the group, so title_main is title.main and
rights_copyright_text is rights.copyright_text. The writer's keys are
@@ -220,6 +222,24 @@ template spineDocFromArtefact() {
mixin spineAbstractionDbRead _dbr;
auto _files = _dbr.dbReadFiles(_artefact, "image");
if (_files.length == 0) { return ""; }
+ /+ ↓ every name checked before anything is created or written.
+ the name comes out of the database and a database can be
+ downloaded, so it is attacker-controlled: it can climb with "..",
+ and chainPath drops everything before an absolute segment, so "/x"
+ would not land under the image directory at all. One bad name means
+ the artefact cannot be trusted for the rest of them, so this
+ refuses the lot rather than skipping one, which is what the zip
+ reader does with a zip.
+ +/
+ foreach (_f; _files) {
+ string _bad = validateCarriedFileName(_f.name);
+ if (_bad.length > 0) {
+ stderr.writeln("WARNING: ", _artefact.baseName,
+ " carries an image spine will not write: ", _bad,
+ "; no image is taken from this artefact");
+ return "";
+ }
+ }
string _root = (tempDir.chainPath("spine-ocda-"
~ _artefact.baseName ~ "-" ~ thisProcessID.to!string).array).to!string;
string _img_dir = (_root.chainPath("media").chainPath("image").array).to!string;
@@ -237,8 +257,18 @@ template spineDocFromArtefact() {
" does not match the digest recorded with it (", _f.sha256, " expected, ",
_got, " found); it is written out as it stands");
}
+ string _out_path = (_img_dir.chainPath(_f.name).array).to!string;
+ /+ ↓ the check on the check: the name rules above already forbid a
+ directory part, so this can only fire if they were loosened
+ +/
+ if (!(carriedPathIsWithin(_img_dir, _out_path))) {
+ stderr.writeln("WARNING: ", _f.name, " in ", _artefact.baseName,
+ " resolves outside the image directory; no image is taken from",
+ " this artefact");
+ return "";
+ }
try {
- (_img_dir.chainPath(_f.name).array).to!string.write(_f.data);
+ _out_path.write(_f.data);
} catch (Exception ex) {
stderr.writeln("WARNING: could not write ", _f.name, ": ", ex.msg);
}