╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ web.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2684 pub fn offerAutoLogin(self: SessionStore, token_hex: *const [token_hex_len]u8) !void { 2685 const file = try self.dir.createFile(self.io, auto_login_name, .{}); 2686 defer file.close(self.io); 2687 try file.writeStreamingAll(self.io, token_hex); 2688 } 2689 2690 pub fn autoLogin(self: SessionStore, out: *[token_hex_len]u8) bool { 2691 out.* = self.auto_login orelse return false; 2692 return true; 2693 } 2694 2695 const auto_login_name = "auto-login"; 2696 2697 // a token is exactly token_hex_len hex chars. validating before using the 2698 // value as a path keeps attacker-supplied cookies from escaping the 2699 // sessions dir (e.g. via "/" or ".." bytes). 2700 fn isToken(token_hex: []const u8) bool { 2701 if (token_hex.len != token_hex_len) return false; 2702 for (token_hex) |c| if (!std.ascii.isHex(c)) return false; 2703 return true; 2704 } 2705 }; 2706