Skip to content

Commit

Permalink
Adds support for secure attribute on token cookie
Browse files Browse the repository at this point in the history
This patch adds support for the secure attribute on token
cookies (sent by nova-novncproxy). If the https is used
to transfer the cookie, the secure attribute is set thus
restricting server requestes to secure conections only.
This should prevent man-in-the-middle attacks.
  • Loading branch information
natsumetakashi authored and dosaboy committed Oct 29, 2013
1 parent 142aa45 commit ad941fa
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions include/webutil.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2013 NTT corp.
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
Expand Down Expand Up @@ -94,16 +95,20 @@ WebUtil.getQueryVar = function(name, defVal) {

// No days means only for this browser session
WebUtil.createCookie = function(name,value,days) {
var date, expires;
var date, expires, secure;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
}
else {
} else {
expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
if (document.location.protocol === "https:") {
secure = "; secure";
} else {
secure = "";
}
document.cookie = name+"="+value+expires+"; path=/"+secure;
};

WebUtil.readCookie = function(name, defaultValue) {
Expand Down

0 comments on commit ad941fa

Please sign in to comment.