Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1156292%22%20slang%3D%22en-US%22%3ESameSite%3DLax%20in%20the%20new%20world%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1156292%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20the%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fiis-support-blog%2Fsamesite-cookie-updates-in-asp-net-or-how-the-net-framework-from%2Fba-p%2F1156246%22%20target%3D%22_self%22%3Elast%20installment%20of%20this%20series%3C%2FA%3E%2C%20we%20discussed%20how%20the%20SameSite%20cookie%20specification%20functioned%20when%20it%20was%20introduced%20and%20how%20it%20has%20changed%20and%20is%20being%20enforced%20starting%20with%20February%20the%204%3CSUP%3Eth%3C%2FSUP%3E%202020.%20In%20this%20article%20we%20try%20and%20understand%20what%20workflows%20may%20be%20impacted%20in%20a%20website%2C%20to%20help%20understand%20if%20you%20should%20take%20any%20action.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20three%20main%20scenarios%20where%20you%20may%20want%20to%20change%20the%20way%20in%20which%20your%20website%20behaves.%20We%20shall%20try%20and%20go%20into%20some%20detail%20in%20each%2C%20and%20see%20what%20can%20be%20done%20to%20ensure%20compliance%20with%20the%20new%20specification.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3EScenario%201%3A%20the%20Session%20cookie%20and%20the%20basket%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20an%20ASP.net%20website%20where%20end%20users%20are%20allowed%20to%20purchase%20goods%20online%2C%20and%20store%20the%20information%20relating%20to%20their%20shopping%20cart%20in%20the%20session%2C%20you%20may%20find%20yourself%20with%20the%20following%20workflow%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EUser%20adds%20an%20item%20to%20their%20cart%20-%26gt%3B%20Item%20is%20added%20to%20the%20session%20and%20a%20cookie%20is%20emitted%20in%20the%20response.%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EUser%20then%20proceeds%20to%20checkout%20-%26gt%3B%20your%20site%20redirects%20the%20user%20to%20a%20payment%20gateway%20-%26gt%3B%20user%20will%20supply%20payment%20details%20-%26gt%3B%20payment%20gateway%20will%20POST%20some%20information%20on%20the%20transaction%20back%20to%20your%20site.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUpon%20POST-ing%20information%20back%2C%20since%20the%20Session%20cookie%20is%20now%20marked%20with%20SameSite%3DLax%2C%20it%20will%20not%20be%20sent%20along%20with%20the%20form.%20Remember%2C%20the%20form%20tag%20is%20received%20along%20with%20the%20response%20from%20the%20payment%20gateway%20site%20after%20the%20user%20has%20entered%20the%20payment%20details%20and%20the%20transaction%20was%20validated%2C%20while%20the%20POST%20data%20is%20sent%20to%20another%20site%20(third%20party%20site%20%E2%80%93%20which%20happens%20to%20be%20your%20e-commerce%20site).%20If%20you%20are%20relying%20on%20the%20Session%20cookie%20being%20present%20when%20processing%20the%20cross-site%20post%20from%20the%20Payment%20gateway%2C%20your%20site%20logic%20will%20break.%20This%20is%20because%20the%20session%20cookie%20is%20now%20marked%20as%20SameSite%3DLax%20by%20ASP.net%20by%20default.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20such%20cases%2C%20changing%20the%20Session%20cookie%20to%20be%20marked%20with%20SameSite%3DNone%20is%20a%20good%20option.%20However%2C%20there%20is%20an%20added%20constraint%3A%20the%20SameSite%20specification%20indicates%20that%20SameSite%3DNone%20attribute%20can%20only%20be%20added%20to%20cookies%20which%20are%20marked%20as%20%E2%80%98secure%E2%80%99%20%E2%80%93%20meaning%20they%20are%20sent%20only%20over%20https%20connections%20and%20not%20over%20http%20connections.%20If%20your%20site%20emits%20a%20Session%20cookie%20marked%20as%20SameSite%3DNone%20over%20a%20non-secure%20connection%2C%20it%20will%20not%20be%20sent%20back%20to%20the%20server%2C%20so%20make%20sure%20all%20communications%20involving%20session%20state%20are%20done%20over%20https.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20easiest%20way%20to%20change%20the%20Session%20cookie%20to%20incorporate%20the%20SameSite%3DNone%20attribute%20is%20to%20change%20the%20configuration%20of%20your%20ASP.net%20website%20in%20the%20web.config%20file%2C%20like%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3CSESSIONSTATE%20cookiesamesite%3D%22None%22%3E%3C%2FSESSIONSTATE%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20that%20this%20will%20only%20add%20the%20SameSite%3DNone%20attribute%20to%20your%20Session%20cookie.%20It%20will%20be%20up%20to%20you%20to%20ensure%20that%20the%20connection%20the%20cookie%20is%20sent%20across%20is%20a%20secure%20connection.%20It%20will%20also%20not%20mitigate%20the%20case%20of%20older%20browsers%2C%20which%20will%20consider%20SameSite%3DNone%20as%20being%20the%20same%20as%20SameSite%3DStrict.%20I%20will%20come%20back%20to%20how%20we%20can%20deal%20with%20this%20is%20code%20in%20a%20later%20installment.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3EScenario%202%3A%20the%20Forms%20authentication%20cookie%20and%20persistent%20authentication%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20scenario%20does%20resemble%20the%20Session%20cookie%20scenario%20to%20some%20extent.%20If%20you%20are%20using%20forms%20based%20authentication%20(not%20ASP.net%20Identity%20%E2%80%93%20which%20we%20may%20touch%20upon%20in%20a%20later%20post)%2C%20and%20you%20have%20given%20your%20users%20the%20option%20to%20check%20the%20%E2%80%98Remember%20me%E2%80%99%20checkbox%20that%20appears%20as%20part%20of%20the%20Login%20control%20on%20a%20WebForms%20site%2C%20or%20are%20just%20persisting%20the%20authentication%20cookie%20for%20longer%20than%20the%20current%20browser%20session%20to%20allow%20users%20to%20remain%20logged%20in%2C%20and%20your%20site%20can%20also%20receive%20requests%20from%20other%20websites%2C%20then%20you%20may%20face%20an%20issue.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOn%20my%20bookmarking%20website%2C%20%3CA%20href%3D%22http%3A%2F%2Fwww.linqto.me%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.linqto.me%3C%2FA%3E%2C%20users%20are%20allowed%20to%20persist%20their%20authentication%20cookie%20and%20remain%20logged%20in%20for%20convenience.%20This%20is%20done%20by%20placing%20a%2030-day%20expiration%20on%20the%20Authentication%20cookie%20when%20it%20is%20emitted%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20312px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F169458i444D1EC6AE0E4EDC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThe%20site%20also%20has%20a%20bookmarklet%20%E2%80%93%20a%20piece%20of%20Javascript%20that%20can%20be%20added%20to%20the%20browser%E2%80%99s%20favorites%20bar%2C%20in%20order%20to%20allow%20users%20to%20bookmark%20any%20site%20they%20are%20navigation%20on%20from%20the%20click%20of%20a%20button.%20Here%20is%20how%20this%20looks%20like%20in%20my%20browser%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20601px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F169459i0D920DFA1CFF5623%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20I%20press%20the%20%E2%80%98Linqto%20Bookmarklet%E2%80%99%20button%2C%20the%20browser%20will%20post%20some%20information%20to%20%3CA%20href%3D%22http%3A%2F%2Fwww.linqto.me%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.linqto.me%3C%2FA%3E%20indicating%20that%20I%20would%20like%20to%20bookmark%20the%20site%20which%20I%20am%20currently%20visiting.%20This%20means%20that%20I%20am%20again%20cross%20posting%20from%20%3CA%20href%3D%22http%3A%2F%2Fwww.flightradar24.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.flightradar24.com%3C%2FA%3E%20in%20this%20case%20to%20%3CA%20href%3D%22http%3A%2F%2Fwww.linqto.me%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.linqto.me%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20I%20expect%20that%20the%20POST%20request%20arrives%20with%20the%20authentication%20cookie%20also%20set%2C%20I%20will%20need%20to%20make%20sure%20that%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20authentication%20cookie%20is%20emitted%20with%20SameSite%3DNone%20as%20an%20attribute%20to%20enable%20cross%20posting%3C%2FLI%3E%0A%3CLI%3EThe%20POST%20by%20the%20bookmarklet%20is%20made%20via%20a%20secure%20connection%20(https)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20this%20is%20not%20the%20case%2C%20I%20will%20not%20be%20authenticated%20on%20my%20website%20when%20doing%20a%20POST%20from%20the%20bookmarklet%2C%20and%20this%20will%20cause%20me%20to%20lose%20the%20data%20from%20the%20POST%20since%20I%20cannot%20associate%20it%20to%20my%20account.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20work%20around%20this%20issue%2C%20a%20second%20piece%20of%20configuration%20can%20be%20added%20to%20the%20web.config%20file%2C%20to%20force%20the%20.Net%20Framework%20to%20emit%20a%20SameSite%3DNone%20attribute%20on%20the%20authentication%20cookie%20when%20using%20Forms%20Authentication%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3CAUTHENTICATION%20mode%3D%22Forms%22%3E%0A%20%20%20%20%3CFORMS%20.....%3D%22%22%20cookiesamesite%3D%22None%22%3E%3C%2FFORMS%3E%0A%3C%2FAUTHENTICATION%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJust%20like%20before%2C%20this%20will%20just%20add%20the%20SameSite%3DNone%20attribute%20to%20all%20authentication%20cookies%20emitted.%20It%20is%20up%20to%20you%20as%20the%20developer%20of%20the%20site%20to%20make%20sure%20the%20cookies%20are%20emitted%20over%20a%20secure%20connection%20(which%20should%20be%20a%20good%20practice%20for%20authentication%20cookies).%20It%20will%20also%20not%20deal%20with%20the%20scenario%20of%20older%20browsers%20which%20will%20interpret%20the%20attribute%20to%20mean%20SameSite%3DStrict%2C%20effectively%20inverting%20the%20behavior%20of%20the%20browser.%20I%20will%20address%20how%20to%20fix%20this%20in%20code%20on%20a%20per%20request%20basis%20later.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3EScenario%203%3A%20The%20Azure%20Active%20Directory%20Authentication%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20an%20ASP.net%20application%20that%20uses%20Azure%20Active%20Directory%20authentication%20or%20any%20other%20type%20of%20federation%20authentication%2C%20like%20ADFS%20for%20example%2C%20the%20authentication%20workflow%20will%20look%20like%20the%20following%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EUser%20request%20the%20application%E2%80%99s%20home%20page.%3C%2FLI%3E%0A%3CLI%3EServer%20detects%20that%20no%20authentication%20cookie%20is%20present%20and%20redirects%20to%20the%20Common%20Authentication%20Endpoint%20(%3CA%20href%3D%22https%3A%2F%2Flogin.microsoftonline.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Flogin.microsoftonline.com%3C%2FA%3E%20in%20the%20case%20of%20Azure%20active%20Directory).%20It%20also%20appends%20several%20cookies%20containing%20information%20about%20the%20login%20attempt.%3C%2FLI%3E%0A%3CLI%3EUser%20Authenticates%20through%20various%20configured%20methods%20to%20the%20common%20authentication%20endpoint%3C%2FLI%3E%0A%3CLI%3EAuthentication%20Endpoint%20sends%20back%20a%20response%20containing%20a%20Form%20element%20that%20will%20POST%20data%20back%20to%20your%20website%20(cross%20posting)%3C%2FLI%3E%0A%3CLI%3EThe%20form%20is%20automatically%20POSTed%20back%20by%20the%20browser%20to%20your%20site.%20If%20the%20cookies%20that%20were%20sent%20to%20the%20client%20following%20the%20first%20request%20are%20not%20returned%2C%20the%20matching%20logic%20will%20fail%2C%20and%20the%20authentication%20will%20return%20an%20error%20from%20your%20application%E2%80%99s%20Authentication%20Middleware.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20602px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F169462i3D95CF28A6A71CE0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ETo%20compensate%20for%20this%20new%20behavior%2C%20starting%20with%20the%20version%204.1.0%20of%20the%20Microsoft.Owin%20Nuget%20package%2C%20we%20can%20configure%20the%20SameSite%20attribute%20and%20the%20%E2%80%98None%E2%80%99%20value%20is%20part%20of%20the%20possible%20values%20for%20the%20enumeration.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3EScenario%204%3A%20All%20other%20cookies%20for%20you%20application%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CBR%20%2F%3EAs%20mentioned%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fiis-support-blog%2Fsamesite-cookie-updates-in-asp-net-or-how-the-net-framework-from%2Fba-p%2F1156246%22%20target%3D%22_self%22%3Efirst%20part%3C%2FA%3E%20of%20this%20article%20series%2C%20these%20cookies%20remain%20unchanged%3A%20they%20do%20not%20receive%20an%20explicit%20SameSite%20attribute%20set%20to%20Lax%20or%20any%20other%20value.%20However%2C%20when%20they%20will%20be%20received%20by%20a%20browser%20implementing%20the%20new%20SameSite%20specification%2C%20like%20Chome%20version%2080%20and%20above%2C%20they%20will%20implicitly%20be%20considered%20as%20SameSite%3DLax%2C%20which%20can%20cause%20some%20of%20them%20to%20not%20be%20sent%20back%20to%20the%20web-server%20as%20described%20in%20the%20table%20of%20behaviors%20described%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fiis-support-blog%2Fsamesite-cookie-updates-in-asp-net-or-how-the-net-framework-from%2Fba-p%2F1156246%22%20target%3D%22_self%22%3Eprevious%20installment%3C%2FA%3E.%3CBR%20%2F%3E%3CBR%20%2F%3EShould%20you%20wish%20for%20a%20SameSite%20attribute%20with%20a%20specific%20value%20to%20be%20added%20to%20these%20cookies%20as%20well%2C%20you%20can%20modify%20the%20web.config%20file%20of%20your%20application%20as%20follows%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3CCONFIGURATION%3E%0A%20%20%3CSYSTEM.WEB%3E%0A%20%20%20%20%3CHTTPCOOKIES%20samesite%3D%22%5BStrict%7CLax%7CNone%7CUnspecified%5D%22%20requiressl%3D%22%5Btrue%7Cfalse%5D%22%3E%3C%2FHTTPCOOKIES%3E%0A%20%20%3CSYSTEM.WEB%3E%0A%3CCONFIGURATION%3E%0A%3C%2FCONFIGURATION%3E%3C%2FSYSTEM.WEB%3E%3C%2FSYSTEM.WEB%3E%3C%2FCONFIGURATION%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESetting%20the%20sameSite%20attribute%20value%20to%20either%20of%20the%20Strict%2C%20Lax%20or%20None%20enumeration%20values%20will%20cause%20a%20SameSite%20attribute%20to%20be%20appended%20on%20all%20cookies%20of%20your%20application%20that%20are%20not%20Authentication%20or%20Session%20related.%20More%20information%20on%20this%20can%20be%20found%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Faspnet%2Fsamesite%2Fsystem-web-samesite%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20%3CBR%20%2F%3E%3CBR%20%2F%3EBe%20careful%20when%20you%20set%20the%20value%20to%20'None'%20and%20also%20set%20the%20requireSSL%20flag%20to%20false%20-%20this%20will%20not%20mark%20the%20cookie%20as%20'Secure'.%20As%20per%20the%20new%20specification%2C%20cookies%20marked%20with%20SameSite%3DNone%20will%20only%20be%20sent%20back%20to%20the%20server%20if%20marked%20as%20secure%20and%20if%20the%20connection%20between%20client%20and%20server%20is%20a%20secure%20connection.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fiis-support-blog%2Fsamesite-in-code-for-your-asp-net-applications%2Fba-p%2F1156361%22%20target%3D%22_self%22%3EIn%20the%20next%20part%3C%2FA%3E%2C%20we%20will%20review%20how%20we%20can%20change%20the%20behavior%20of%20ASP.net%20using%20code%20to%20also%20address%20the%20scenarios%20above.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ewritten%20by%3A%20%3CA%20href%3D%22http%3A%2F%2Flinqto.me%2Fabout%2Fpcociuba%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPaul%20Cociuba%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1156292%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20the%20last%20installment%20of%20this%20series%2C%20we%20discussed%20how%20the%20SameSite%20cookie%20specification%20functioned%20when%20it%20was%20introduced%20and%20how%20it%20has%20changed%20and%20is%20being%20enforced%20starting%20with%20February%20the%204%3CSUP%3Eth%3C%2FSUP%3E%202020.%20In%20this%20article%20we%20try%20and%20understand%20what%20workflows%20may%20be%20impacted%20in%20a%20website%2C%20to%20help%20understand%20if%20you%20should%20take%20any%20action.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft

In the last installment of this series, we discussed how the SameSite cookie specification functioned when it was introduced and how it has changed and is being enforced starting with February the 4th 2020. In this article we try and understand what workflows may be impacted in a website, to help understand if you should take any action.

 

There are three main scenarios where you may want to change the way in which your website behaves. We shall try and go into some detail in each, and see what can be done to ensure compliance with the new specification.

 

Scenario 1: the Session cookie and the basket

 

If you have an ASP.net website where end users are allowed to purchase goods online, and store the information relating to their shopping cart in the session, you may find yourself with the following workflow:

 

User adds an item to their cart -> Item is added to the session and a cookie is emitted in the response.

User then proceeds to checkout -> your site redirects the user to a payment gateway -> user will supply payment details -> payment gateway will POST some information on the transaction back to your site.

 

Upon POST-ing information back, since the Session cookie is now marked with SameSite=Lax, it will not be sent along with the form. Remember, the form tag is received along with the response from the payment gateway site after the user has entered the payment details and the transaction was validated, while the POST data is sent to another site (third party site – which happens to be your e-commerce site). If you are relying on the Session cookie being present when processing the cross-site post from the Payment gateway, your site logic will break. This is because the session cookie is now marked as SameSite=Lax by ASP.net by default.

 

In such cases, changing the Session cookie to be marked with SameSite=None is a good option. However, there is an added constraint: the SameSite specification indicates that SameSite=None attribute can only be added to cookies which are marked as ‘secure’ – meaning they are sent only over https connections and not over http connections. If your site emits a Session cookie marked as SameSite=None over a non-secure connection, it will not be sent back to the server, so make sure all communications involving session state are done over https.

 

The easiest way to change the Session cookie to incorporate the SameSite=None attribute is to change the configuration of your ASP.net website in the web.config file, like the following:

 

<sessionState cookieSameSite="None" />

 

Note that this will only add the SameSite=None attribute to your Session cookie. It will be up to you to ensure that the connection the cookie is sent across is a secure connection. It will also not mitigate the case of older browsers, which will consider SameSite=None as being the same as SameSite=Strict. I will come back to how we can deal with this is code in a later installment.

 

Scenario 2: the Forms authentication cookie and persistent authentication

 

This scenario does resemble the Session cookie scenario to some extent. If you are using forms based authentication (not ASP.net Identity – which we may touch upon in a later post), and you have given your users the option to check the ‘Remember me’ checkbox that appears as part of the Login control on a WebForms site, or are just persisting the authentication cookie for longer than the current browser session to allow users to remain logged in, and your site can also receive requests from other websites, then you may face an issue.

 

On my bookmarking website, www.linqto.me, users are allowed to persist their authentication cookie and remain logged in for convenience. This is done by placing a 30-day expiration on the Authentication cookie when it is emitted:

 

image.png

The site also has a bookmarklet – a piece of Javascript that can be added to the browser’s favorites bar, in order to allow users to bookmark any site they are navigation on from the click of a button. Here is how this looks like in my browser:

 

image.png

 

If I press the ‘Linqto Bookmarklet’ button, the browser will post some information to www.linqto.me indicating that I would like to bookmark the site which I am currently visiting. This means that I am again cross posting from www.flightradar24.com in this case to www.linqto.me.

 

If I expect that the POST request arrives with the authentication cookie also set, I will need to make sure that:

  • The authentication cookie is emitted with SameSite=None as an attribute to enable cross posting
  • The POST by the bookmarklet is made via a secure connection (https)

 

If this is not the case, I will not be authenticated on my website when doing a POST from the bookmarklet, and this will cause me to lose the data from the POST since I cannot associate it to my account.

 

To work around this issue, a second piece of configuration can be added to the web.config file, to force the .Net Framework to emit a SameSite=None attribute on the authentication cookie when using Forms Authentication:

 

<authentication mode="Forms">
    <forms ..... cookieSameSite="None" />
</authentication>

 

Just like before, this will just add the SameSite=None attribute to all authentication cookies emitted. It is up to you as the developer of the site to make sure the cookies are emitted over a secure connection (which should be a good practice for authentication cookies). It will also not deal with the scenario of older browsers which will interpret the attribute to mean SameSite=Strict, effectively inverting the behavior of the browser. I will address how to fix this in code on a per request basis later.

 

Scenario 3: The Azure Active Directory Authentication

 

If you have an ASP.net application that uses Azure Active Directory authentication or any other type of federation authentication, like ADFS for example, the authentication workflow will look like the following:

  1. User request the application’s home page.
  2. Server detects that no authentication cookie is present and redirects to the Common Authentication Endpoint (https://login.microsoftonline.com in the case of Azure active Directory). It also appends several cookies containing information about the login attempt.
  3. User Authenticates through various configured methods to the common authentication endpoint
  4. Authentication Endpoint sends back a response containing a Form element that will POST data back to your website (cross posting)
  5. The form is automatically POSTed back by the browser to your site. If the cookies that were sent to the client following the first request are not returned, the matching logic will fail, and the authentication will return an error from your application’s Authentication Middleware.

image.png

To compensate for this new behavior, starting with the version 4.1.0 of the Microsoft.Owin Nuget package, we can configure the SameSite attribute and the ‘None’ value is part of the possible values for the enumeration.

Scenario 4: All other cookies for you application

As mentioned in the first part of this article series, these cookies remain unchanged: they do not receive an explicit SameSite attribute set to Lax or any other value. However, when they will be received by a browser implementing the new SameSite specification, like Chome version 80 and above, they will implicitly be considered as SameSite=Lax, which can cause some of them to not be sent back to the web-server as described in the table of behaviors described in the previous installment.

Should you wish for a SameSite attribute with a specific value to be added to these cookies as well, you can modify the web.config file of your application as follows:

<configuration>
  <system.web>
    <httpCookies sameSite="[Strict|Lax|None|Unspecified]" requireSSL="[true|false]" />
  <system.web>
<configuration>

Setting the sameSite attribute value to either of the Strict, Lax or None enumeration values will cause a SameSite attribute to be appended on all cookies of your application that are not Authentication or Session related. More information on this can be found here.

Be careful when you set the value to 'None' and also set the requireSSL flag to false - this will not mark the cookie as 'Secure'. As per the new specification, cookies marked with SameSite=None will only be sent back to the server if marked as secure and if the connection between client and server is a secure connection.

 

In the next part, we will review how we can change the behavior of ASP.net using code to also address the scenarios above.

 

written by: Paul Cociuba