Validate a cookie domain ASCII string
323335
def valid_domain(domain):
    ""
    # Using encoding on domain would confuse browsers into not sending cookies.
    # Generate UnicodeDecodeError up front if it can't store as ASCII.
    domain.encode('ascii')
    # Domains starting with periods are not RFC-valid, but this is very common
    # in existing cookies, so they should still parse with DOMAIN_AV.
    if Definitions.DOMAIN_RE.match(domain):
        return True
    return False
1286357
def valid_name(name):
    ""
    if isinstance(name, bytes):
        name = name.decode('ascii')
    if not Definitions.COOKIE_NAME_RE.match(name):
        return False
    # This module doesn't support $identifiers, which are part of an obsolete
    # and highly complex standard which is never used.
    if name[0] == "$":
        return False
    return True
550278
function (user_id, cookie, passphrase, callback) {
		var packed_user_id = String.fromCharCode(0, 0, 0, 0, user_id >> 24 & 0xFF, user_id >> 16 & 0xFF, user_id >> 8 & 0xFF, user_id & 0xFF);
		var client_nonce = "";
		for (var i = 0; i < 16; ++i) {
			client_nonce += String.fromCharCode(Math.random() * 256);
		}
		var seed = packed_user_id + unescape(encodeURIComponent(passphrase));
		var data = packed_user_id + _server_nonce + client_nonce;
		var d = ecp.mpn_pack(util.hash_string_to_words(seed));
		var z = ecp.mpn_pack(util.hash_string_to_words(data));
		var r = ecp.mpn_new(8), s = ecp.mpn_new(8);
		ecp.ecp_sign(r, s, ecp.secp224k1_p, ecp.secp224k1_a, ecp.secp224k1_G, ecp.secp224k1_n, d, z, 8);
		request({
			method: "Authenticate",
			user_id: user_id,
			cookie: cookie,
			nonce: btoa(client_nonce),
			signature: [ btoa(util.words_to_string(ecp.mpn_unpack(r))), btoa(util.words_to_string(ecp.mpn_unpack(s))) ],
		}, callback);
	}
1047863
private static BitSet validCookieNameOctets() {
        BitSet bits = new BitSet();
        for (int i = 32; i < 127; i++) {
            bits.set(i);
        }
        int[] separators = new int[]
                { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', '\t' };
        for (int separator : separators) {
            bits.set(separator, false);
        }
        return bits;
    }
561929
public String getUnencodedHtmlCookieString(String name, String value, Map<String, String> cookieProperties) {
        return createHtmlCookieString(name, value, cookieProperties, false);
    }
1358649
private static BitSet validCookieValueOctets() {
        BitSet bits = new BitSet(8);
        for (int i = 35; i < 127; i++) {
            // US-ASCII characters excluding CTLs (%x00-1F / %x7F)
            bits.set(i);
        }
        bits.set('"', false);  // exclude DQUOTE = %x22
        bits.set(',', false);  // exclude comma = %x2C
        bits.set(';', false);  // exclude semicolon = %x3B
        bits.set('\\', false); // exclude backslash = %x5C
        return bits;
    }
884749
private Cookie convertCookieString(String cookieString) {
        Cookie cookie = new Cookie(getCookieParam(NAME, cookieString), getCookieParam(VALUE, cookieString));

        if (cookieString.contains(COMMENT)) {
            cookie.setComment(getCookieParam(COMMENT, cookieString));
        }

        if (cookieString.contains(PATH)) {
            cookie.setPath(getCookieParam(PATH, cookieString));
        }

        if (cookieString.contains(DOMAIN)) {
            cookie.setDomain(getCookieParam(DOMAIN, cookieString));
        }

        if (cookieString.contains(MAX_AGE)) {
            cookie.setMaxAge(Integer.valueOf(getCookieParam(MAX_AGE, cookieString)));
        }

        if (cookieString.contains(SECURE)) {
            cookie.setSecure(Boolean.valueOf(getCookieParam(SECURE, cookieString)));
        }

        if (cookieString.contains(VERSION)) {
            cookie.setVersion(Integer.valueOf(getCookieParam(VERSION, cookieString)));
        }

        if (cookieString.contains(HTTP_ONLY)) {
            cookie.setHttpOnly(Boolean.valueOf(getCookieParam(HTTP_ONLY, cookieString)));
        }

        return cookie;
    }
229046
private void parseIDFromCookies(RequestMessage request) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Looking for ID in cookies");
        }
        Enumeration<String> list = request.getHeaders("Cookie");
        while (list.hasMoreElements()) {
            String item = list.nextElement();
            int index = item.indexOf(getSessionConfig().getIDName());
            if (-1 != index) {
                index = item.indexOf('=', index);
                if (-1 != index) {
                    index++;
                    // TODO this is assuming that the full value is valid and
                    // grabbing just the 4 digit id...
                    if (item.length() >= (index + 4)) {
                        this.id = item.substring(index, index + 4);
                        this.fromCookie = true;
                        break;
                    }
                }
            }
        }
    }
138416
function _fnReadCookie ( sName )
		{
			var
				aParts = window.location.pathname.split('/'),
				sNameEQ = sName + '_' + aParts[aParts.length-1].replace(/[\/:]/g,"").toLowerCase() + '=',
			 	sCookieContents = document.cookie.split(';');
			
			for( var i=0 ; i<sCookieContents.length ; i++ )
			{
				var c = sCookieContents[i];
				
				while (c.charAt(0)==' ')
				{
					c = c.substring(1,c.length);
				}
				
				if (c.indexOf(sNameEQ) === 0)
				{
					return decodeURIComponent( c.substring(sNameEQ.length,c.length) );
				}
			}
			return null;
		}
591285
def _decode_xsrf_token(
        self, cookie: str
    ) -> Tuple[Optional[int], Optional[bytes], Optional[float]]:
        

        try:
            m = _signed_value_version_re.match(utf8(cookie))

            if m:
                version = int(m.group(1))
                if version == 2:
                    _, mask_str, masked_token, timestamp_str = cookie.split("|")

                    mask = binascii.a2b_hex(utf8(mask_str))
                    token = _websocket_mask(mask, binascii.a2b_hex(utf8(masked_token)))
                    timestamp = int(timestamp_str)
                    return version, token, timestamp
                else:
                    # Treat unknown versions as not present instead of failing.
                    raise Exception("Unknown xsrf cookie version")
            else:
                version = 1
                try:
                    token = binascii.a2b_hex(utf8(cookie))
                except (binascii.Error, TypeError):
                    token = utf8(cookie)
                # We don't have a usable timestamp in older versions.
                timestamp = int(time.time())
                return (version, token, timestamp)
        except Exception:
            # Catch exceptions and return nothing instead of failing.
            gen_log.debug("Uncaught exception in _decode_xsrf_token", exc_info=True)
            return None, None, None
457067
protected String encodeCookie(SerializableHttpCookie cookie) {
        if (cookie == null)
            return null;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(os);
            outputStream.writeObject(cookie);
        } catch (IOException e) {
            Util.log("IOException in encodeCookie", e);
            return null;
        }

        return byteArrayToHexString(os.toByteArray());
    }
1037958
protected Cookie decodeCookie(String cookieString) {
        byte[] bytes = hexStringToByteArray(cookieString);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        Cookie cookie = null;
        try {
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
        } catch (IOException e) {
            Util.log("IOException in decodeCookie", e);
        } catch (ClassNotFoundException e) {
            Util.log("ClassNotFoundException in decodeCookie", e);
        }

        return cookie;
    }
1242391
private Optional<String> getXsrfFromHtmlBody(HttpResponse loginResponse) throws IOException {
        Optional<Cookie> gerritAccountCookie = findGerritAccountCookie();
        if (gerritAccountCookie.isPresent()) {
            Matcher matcher = GERRIT_AUTH_PATTERN.matcher(EntityUtils.toString(loginResponse.getEntity(), Consts.UTF_8));
            if (matcher.find()) {
                return Optional.of(matcher.group(1));
            }
        }
        return Optional.absent();
    }
106254
function cookiee(secret, opt) {

  if (!secret) {
    throw new TypeError('secret required');
  }
  var options = opt || Object.create(null);
  var my = {
    secret: Buffer.isBuffer(secret) ? secret : new Buffer(secret),
    cipher: String(options.cipher || 'arc4'),
    cookie: String(options.cookie || 'vault'),
    domain: String(options.domain || ''),
    path: String(options.path || '/'),
    maxAge: Number(options.maxAge) || 1000 * 3600 * 24 * 365,
    httpOnly: Boolean(options.httpOnly),
    secure: Boolean(options.secure),
    signed: Boolean(options.signed),
    encoding: String(options.encoding || 'hex'),
    extra: Array.isArray(options.extra) === true ? options.extra : []
  };

  return Boolean(options.signed) ? new Signed(my) : new Normal(my);
}
642688
def _validated(self, value):
        """"""
        if value is None:
            return None
        if isinstance(value, uuid.UUID):
            return value
        try:
            if isinstance(value, bytes) and len(value) == 16:
                return uuid.UUID(bytes=value)
            else:
                return uuid.UUID(value)
        except (ValueError, AttributeError, TypeError):
            self.fail('invalid_uuid')
1263938
def force_ascii_values(data):
    """"""
    return {
        k: v.encode('utf8').decode('ascii', 'backslashreplace')
        for k, v in data.items()
    }
1152979
function(sId) {

			//Match camelCase - case sensitive
			var idRegEx = /^[a-z][a-zA-Z]+$/;

			if (
				!sId || typeof sId !== 'string') {
				return false;
			}

			if (sId.match(idRegEx) && this.validateStringLength(sId, 6, 50)) {
				return true;
			}

			return false;
	}