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

  • SEARCH
  • Home
  • 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 7002987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:00:06+00:00 2026-05-27T21:00:06+00:00

I have some Ruby web apps that use OpenID for authentication and store the

  • 0

I have some Ruby web apps that use OpenID for authentication and store the session in a cookie. There are a few API- and AJAX- related things that my Ruby frameworks aren’t a good fit for, so I’ve got some node.js services. The problem is that if someone knew the URLs of my AJAX services, they’d basically be open to the public as things stand. At the moment those services do a simple check of the Origin header, but obviously that’s very easy to forge.

So I want to be able to restrict access to the services running on Node (or Python, or in a non-Rack based Ruby service, or anything else) to users who are logged into the ‘main’ service that’s run through a Rack-based web application. Are there any conventions for how this sort of thing is done? I’ve seen heaps of websites that will serve content and pages through example.com, and then the AJAX calls get made through api.example.com, so I’m surprised this is something I’ haven’t read about.

I do have an idea for how to do this, and I’d love some feedback on whether I’m missing something blindingly obvious that makes this insecure:

My Ruby web app uses OpenID for authentication and stores the session in a session cookie using Rack::Session. From looking at the Rack::Session source, my framework seems to go through this process:

  • generate a Marshal dump of my User object
  • generate a SHA1 hash of the Marshal based on a secret key
  • store a hex digest of the SHA1 hash in a cookie

So theoretically I could have a pre-arranged key or system for generating the key, or some message passing between frameworks through a secure channel to share the key. Then I could reverse the encryption process in any other framework that wanted to be able to verify session data. I’d have to get rid of the first step and only store JSON data or something instead of a Ruby object for cross-language compatibility, of course.

Is this considered a secure way to do things, assuming the protocols for sharing the key are appropriately secure?

  • 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-05-27T21:00:07+00:00Added an answer on May 27, 2026 at 9:00 pm

    What you’re describing is a Message Authentication Code (MAC); in this case, it’s a Hash-based MAC or HMAC. Basically, take a representation of the data you want to authenticate (make sure is coming from a certain source), append a secret key to it, and hash the whole thing. Then attach that computed hash to the message (what you just hashed minus the secret key). When the receiving party receives the message, it would take the data, append the same shared secret to it, and hash it. If that computed value is the same as the one received as part of the message, it is authentic and should be processed; if the hashes do not match, it is not from the party it should be from and should be discarded.

    You may want to look at the RFC specifying the HMAC construct (just don’t use the sample code as it still uses MD5; use something like SHA-256 or SHA-512 to implement your HMAC):
    http://www.ietf.org/rfc/rfc2104.txt

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

Sidebar

Related Questions

I've done some Python but have just now starting to use Ruby I could
Greetings! I have some troubles enabling OAuth authentication for my web application running on
Some of the users of our Ruby on Rails app have complained that page
I'm interested in creating some web apps that simulate results based on data. For
So, I've started to create some Ruby unit tests that use Selenium RC to
I have some ideas for web apps. Sadly, I have very little knowledge of
I have some Ruby code which takes dates on the command line in the
I am running Ruby and MySQL on a Windows box. I have some Ruby
I have some difficulties for using Ruby block, passing in a method. As in
I have done some work with Ruby on Rails but am still not comfortable

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.