Avatar billede alex_sleiborg Nybegynder
23. oktober 2008 - 14:33 Der er 7 kommentarer

Er sessions sikre?

Vi bruger ASP.NET MVC til at lave et softwareprojekt med. Vi skal lave et ganske almindeligt brugersystem (login, registrering, osv.) og vil gerne høre om sessions er sikre nok. En meget simpel måde at se om man er logget ind på er ved at gemme brugernavnet i en session-variabel men er dette sikkert nok? Er det muligt at kopiere session-id'en (cookien) over til en anden pc og dermed snyde systemet eller vil ASP.NET sørge for at det er den rigtige bruger?

Sådan skriver vi til session-variablen:
HttpContext.Session["username"] = userName;

Sådan læser vi fra session-variablen:
string username = (string)HttpContext.Current.Session["username"];

På forhånd tak!
Avatar billede jokkejensen Novice
23. oktober 2008 - 15:28 #1
Hej..

Sessions styres gennem et session id, cookien indeholder kun session id, resten ligger i applikationen.. sikkert ram..

Man vil godt kunne flytte en session til anden browser - Men sessionid'et er tilfældigt hvergang, og eksisterer kun indtil Session.Timeout.. Mht til at flytte session til en anden browser tænker jeg at der skal noget hacking osv til, men rettighedsstyring foregår af hvad jeg ved gennem session, det benyttes af de store web systemer jeg kender til.

Man kan sætte sessions leve tid globalt i web.config, sæt den evt lavt, og asynkront forny den så længe browser er åben. Så vil man ikke blive logget ud ved inaktivtet, først når browseren lukkes.

/J
Avatar billede jokkejensen Novice
23. oktober 2008 - 15:30 #2
Desuden ser jeg ikke andre "simple" muligheder, og er overbevist om det er sikkert.
Avatar billede jokkejensen Novice
23. oktober 2008 - 15:33 #3
Lidt fra Msdn: http://msdn.microsoft.com/en-us/library/aa479314.aspx

Thumbs Up
In ASP.NET, session management and forms authentication are the only two system features that use cookies under the hood. With cookieless sessions, you can now deploy stateful applications that work regardless of the user's preferences about cookies. As of ASP.NET 1.x, though, cookies are still required to implement forms authentication. The good news is that in ASP.NET 2.0 forms authentication can optionally work in a cookieless fashion.

Another common reason advanced against cookies is security. This is a point that deserves a bit more attention.

Cookies are inert text files and as such can be replaced or poisoned by hackers, should they gain access to a machine. The real threat lies not much in what cookies can install on your client machine, but in what they can upload to the target site. Cookies are not programs and never run like programs; other software that gets installed on your machine, though, can use the built-in browser support for cookies to do bad things remotely.

Furthermore, cookies are at risk of theft. Once stolen, a cookie that contains valuable and personal information can disclose its contents to malicious hackers and favor other types of Web attacks. In summary, by using cookies you expose yourself to risks that can be zeroed off otherwise. Really?

Thumbs Down
Let's look at security from another perspective. Have you ever heard of session hijacking? If not, take a look at the TechNet Magazine article Theft On The Web: Prevent Session Hijacking. In brief, session hijacking occurs when an attacker gains access to the session state of a particular user. Basically, the attacker steals a valid session ID and uses that to get into the system and snoop into the data. One common way to get a valid session ID is stealing a valid session cookie. That said, if you think that cookieless sessions put your application on the safe side, you're deadly wrong. With cookieless sessions, in fact, the session ID shows up right in the address bar! Try the following:

Connect to a Web site that uses cookieless sessions—for example, MapPoint—and get a map. At this point, the address is stored in the session state.
Grab the URL up to the page name. Don't include the query string but make sure the URL includes the session ID.
Save the URL to a file and copy/send the file to another machine.
On the second machine, open the file and paste the URL in a new instance of the browser.
The same map shows up as long as the session timeout is still valid.
With cookieless sessions, stealing session IDs is easier than ever.

I believe we all agree that stealing sessions is a reprehensible action from an ethical point of view. But is it injurious as well? That depends on what is actually stored in the session state. Stealing a session ID per se doesn't execute an action out of the code control. But it could disclose private data to unauthorized users and enable the bad guy to execute unauthorized operations. Read Wicked Code: Foiling Session Hijacking Attempts for tips on how to block session hijacking in ASP.NET applications. (And, yes, it doesn't rely on cookieless sessions!)

Using cookieless sessions also raises issues with links. For example, you can't have absolute, fully qualified links in your ASP.NET pages. If you do this, each request that originates from that hyperlink will be considered as part of a new session. Cookieless sessions require that you always use relative URLs, like in ASP.NET postbacks. You can use a fully qualified URL only if you can embed the session ID in it. But how can you do that, since session IDs are generated at run time?

The following code breaks the session:

<a runat="server" href="/test/page.aspx">Click</a>
To use absolute URLs, resort to a little trick that uses the ApplyAppPathModifier method on the HttpResponse class:

<a runat="server"
    href=<% =Response.ApplyAppPathModifier("/test/page.aspx")%> >Click</a>
The ApplyAppPathModifier method takes a string representing a URL and returns an absolute URL that embeds session information. For example, this trick is especially useful in situations in which you need to redirect from a HTTP page to an HTTPS page. Finally, be conscious that every time you type a path to a site from within the same browser you're going to lose your state with cookieless sessions. As a further warning, be aware that cookieless sessions can be problematic with mobile applications if the device can't handle the specially formatted URL.
Avatar billede jokkejensen Novice
23. oktober 2008 - 15:39 #4
Jeg syntes dog at cookieless sessionid kun skal bruges til enheder der ikke understøtter cookies.

Men vil du forbedre sikkerheden bare lidt, kunne du evt gemme sessionid, ip, og browser egenskaber i en db - ex gennem global.asax Session_Start.

Lav så et check for hvert request, de variabler skulle ikke gerne ændre sig. Deaktiver rækken i app.Session_end.

Men jeg tror ikke det er nødvendigt.
Avatar billede jokkejensen Novice
23. oktober 2008 - 15:42 #5
nå, det er samme forslag der er her : http://msdn.microsoft.com/da-dk/magazine/cc300500(en-us).aspx
Avatar billede alex_sleiborg Nybegynder
13. november 2008 - 13:19 #6
Sorry for det sene svar. Men mange tak fordi du gad at uddybe det:) Gider du smide et svar. Og mange tak
Avatar billede alex_sleiborg Nybegynder
02. december 2008 - 10:32 #7
Jokke jensen. Gider du ikke smide et svar:)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester