╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ web.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
3154 // leave `token_hex`'s session for visitors arriving without one. only the 3155 // `try` fixture writes one. the name can't collide with a session token. 3156 pub fn offerAutoLogin(self: SessionStore, token_hex: *const [token_hex_len]u8) !void { 3157 const file = try self.dir.createFile(self.io, auto_login_name, .{}); 3158 defer file.close(self.io); 3159 try file.writeStreamingAll(self.io, token_hex); 3160 } 3161 3162 pub fn autoLogin(self: SessionStore, out: *[token_hex_len]u8) bool { 3163 out.* = self.auto_login orelse return false; 3164 return true; 3165 } 3166 3167 const auto_login_name = "auto-login"; 3168 3169 // a token is exactly token_hex_len hex chars. validating before using the 3170 // value as a path keeps attacker-supplied cookies from escaping the 3171 // sessions dir (e.g. via "/" or ".." bytes). 3172 fn isToken(token_hex: []const u8) bool { 3173 if (token_hex.len != token_hex_len) return false; 3174 for (token_hex) |c| if (!std.ascii.isHex(c)) return false; 3175 return true; 3176 } 3177 }; 3178