Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:26:13+00:00 2026-06-11T15:26:13+00:00

I am using Ruby and Sinatra to develop an application. I use enable :sessions

  • 0

I am using Ruby and Sinatra to develop an application.
I use

enable :sessions

in order to use the session variable provided by rack. How can I make all of the session cookies be HTTPOnly? Is it like this by default? I can’t find any documentation on this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:26:14+00:00Added an answer on June 11, 2026 at 3:26 pm

    Instead of enable :sessions:

    use Rack::Session::Cookie, {:httponly => true }
    

    I’d suggest using the encrypted_cookie gem instead, it’s far more secure. As an example, here’s what I’ll probably have for a project:

    # app/main.rb
    module Example
      class App < Sinatra::Base # this class in its own file
        # stuff here
      end
    end
    
    # app/config.rb
    require "main"
    module Example
      def self.app #
        Rack::Builder.app do
          cookie_settings = {        
            :key          => 'usr',
            :path         => "/",
            :expire_after => 86400,             # In seconds, 1 day.
            :secret       => ENV["COOKIE_KEY"], # load this into the environment of the server
            :httponly     => true
          }
          cookie_settings.merge!( :secure => true ) if ENV["RACK_ENV"] == "production"
    
          # AES encryption of cookies
          use Rack::Session::EncryptedCookie, cookie_settings
    
          # other stuff here
    
          run App
        end
      end
    end
    
    # config.ru
    require "app/config"
    run Example.app  # this in the rackup file
    

    (To clarify why I’ve laid it out this way – this kind of stucture allows me to split the app up and use it easier in tests by just requiring the app/config.rb. YMMV)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an Ruby application using Sinatra (over Rack/Thin) and I want to
I am using ruby 1.9.2 and sinatra 1.3.2, Datamapper I get error: can't convert
Using Sinatra in Ruby you can set the server's settings by doing: set :myvariable,
I'm very new to Ruby and using Sinatra, mainly so that I can do
I'm trying to build an app using Sinatra, Ruby, rack, haml, pony and SendGrid,
I'm building an application in ruby using the sinatra framework and am having trouble
I'm trying to migrate a sinatra application to ruby 1.9 I'm using sinatra 1.0,
My web app is using Rack 1.4.0, Sinatra v1.2.6, Thin v1.2.11, Ruby v1.9.2p180 Navigating
I have test app written on ruby, using Sinatra+Sequel. config.ru: require './main' run Sinatra::Application
I'm building a small Ruby application using DataMapper and Sinatra, and I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.