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