Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path traversal bug when creating events #455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/calendars/FullNoteCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EventPathLocation } from "../core/EventStore";
import { ObsidianInterface } from "../ObsidianAdapter";
import { OFCEvent, EventLocation, validateEvent } from "../types";
import { EditableCalendar, EditableEventResponse } from "./EditableCalendar";
import { join } from "path";

const basenameFromEvent = (event: OFCEvent): string => {
switch (event.type) {
Expand Down Expand Up @@ -216,7 +217,14 @@ export default class FullNoteCalendar extends EditableCalendar {
}

async createEvent(event: OFCEvent): Promise<EventLocation> {
const path = `${this.directory}/${filenameForEvent(event)}`;
const event_filename = filenameForEvent(event);
const path = join(this.directory, event_filename);

if (!path.startsWith(this.directory)) {
throw new Error(
`Event at ${path} will not be in calendar directory.`
);
}
if (this.app.getAbstractFileByPath(path)) {
throw new Error(`Event at ${path} already exists.`);
}
Expand Down