╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ web.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2640 const file = try self.dir.createFile(self.io, auto_login_name, .{}); 2641 defer file.close(self.io); 2642 try file.writeStreamingAll(self.io, token_hex); 2643 } 2644 2645 pub fn autoLogin(self: SessionStore, out: *[token_hex_len]u8) bool { 2646 out.* = self.auto_login orelse return false; 2647 return true; 2648 } 2649 2650 const auto_login_name = "auto-login"; 2651 2652 // a token is exactly token_hex_len hex chars. validating before using the 2653 // value as a path keeps attacker-supplied cookies from escaping the 2654 // sessions dir (e.g. via "/" or ".." bytes). 2655 fn isToken(token_hex: []const u8) bool { 2656 if (token_hex.len != token_hex_len) return false; 2657 for (token_hex) |c| if (!std.ascii.isHex(c)) return false; 2658 return true; 2659 } 2660 }; 2661