╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ web.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2926 if (!isToken(token_hex)) return; 2927 self.dir.deleteFile(self.io, token_hex) catch {}; 2928 } 2929 2930 // leave `token_hex`'s session for visitors arriving without one. only the 2931 // `try` fixture writes one. the name can't collide with a session token. 2932 pub fn offerAutoLogin(self: SessionStore, token_hex: *const [token_hex_len]u8) !void { 2933 const file = try self.dir.createFile(self.io, auto_login_name, .{}); 2934 defer file.close(self.io); 2935 try file.writeStreamingAll(self.io, token_hex); 2936 } 2937 2938 pub fn autoLogin(self: SessionStore, out: *[token_hex_len]u8) bool { 2939 out.* = self.auto_login orelse return false; 2940 return true; 2941 } 2942 2943 const auto_login_name = "auto-login"; 2944 2945 // a token is exactly token_hex_len hex chars. validating before using the 2946 // value as a path keeps attacker-supplied cookies from escaping the 2947 // sessions dir (e.g. via "/" or ".." bytes). 2948 fn isToken(token_hex: []const u8) bool { 2949 if (token_hex.len != token_hex_len) return false; 2950 for (token_hex) |c| if (!std.ascii.isHex(c)) return false; 2951 return true; 2952 } 2953 }; 2954