╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ web.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
781 if (!isToken(token_hex)) return false; 782 const file = self.dir.openFile(self.io, token_hex, .{ .mode = .read_only }) catch return false; 783 defer file.close(self.io); 784 var storage: [evt.event_id_size]u8 = undefined; 785 var file_reader = file.reader(self.io, &storage); 786 file_reader.interface.readSliceAll(out) catch return false; 787 return true; 788 } 789 790 // revoke a session. a no-op for a missing or malformed token. 791 pub fn remove(self: SessionStore, token_hex: []const u8) void { 792 if (!isToken(token_hex)) return; 793 self.dir.deleteFile(self.io, token_hex) catch {}; 794 } 795 796 // a token is exactly token_hex_len hex chars. validating before using the 797 // value as a path keeps attacker-supplied cookies from escaping the 798 // sessions dir (e.g. via "/" or ".." bytes). 799 fn isToken(token_hex: []const u8) bool { 800 if (token_hex.len != token_hex_len) return false; 801 for (token_hex) |c| if (!std.ascii.isHex(c)) return false; 802 return true; 803 } 804 }; 805