╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ web.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1178 if (!isToken(token_hex)) return false; 1179 const file = self.dir.openFile(self.io, token_hex, .{ .mode = .read_only }) catch return false; 1180 defer file.close(self.io); 1181 var storage: [evt.event_id_size]u8 = undefined; 1182 var file_reader = file.reader(self.io, &storage); 1183 file_reader.interface.readSliceAll(out) catch return false; 1184 return true; 1185 } 1186 1187 // revoke a session. a no-op for a missing or malformed token. 1188 pub fn remove(self: SessionStore, token_hex: []const u8) void { 1189 if (!isToken(token_hex)) return; 1190 self.dir.deleteFile(self.io, token_hex) catch {}; 1191 } 1192 1193 // a token is exactly token_hex_len hex chars. validating before using the 1194 // value as a path keeps attacker-supplied cookies from escaping the 1195 // sessions dir (e.g. via "/" or ".." bytes). 1196 fn isToken(token_hex: []const u8) bool { 1197 if (token_hex.len != token_hex_len) return false; 1198 for (token_hex) |c| if (!std.ascii.isHex(c)) return false; 1199 return true; 1200 } 1201 }; 1202