Can't send cookie in header

Hello!

I’m trying to make a patch request which ranks a user if they own a specific game pass, however I can’t seem to be getting it working.

I’m using ProxyService:

Anyway, this is essentially what I’m doing (running in the command bar), cookie is obviously not shown but yeah:

local players = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')
local httpService = game:GetService('HttpService')

local playerData = replicatedStorage:WaitForChild('PlayerData')

local serverModules = game.ServerScriptService:WaitForChild('ServerModules')
local module = require(serverModules:WaitForChild('ProxyHandler'))

local proxy = module:New('https://swecdewc.herokuapp.com/', '')

local cookie = [[_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_]]

local url = 'https://groups.roblox.com/v1/groups/6883697/users/%u&groupId=6883697&userId=%u'

local headerName = '.ROBLOSECURITY'

print(proxy:Patch(
	url:format(1562331890, 1562331890),
	httpService:JSONEncode({['roleId'] = 2;}),
	Enum.HttpContentType.ApplicationJson,
	false,
	{
		[headerName] = cookie
	}
))

Order of arguments is:
URL,
data (which I am pretty sure is body),
ContentType,
Compress,
Headers

Errors with Header ".ROBLOSECURITY" has unallowed character ".", I tried replacing .ROBLOSECURITY with “Cookie”, but then it said the cookie was disallowed because of the “|” character. Any ideas?

This is because you are doing cookies wrong. Cookies should be in a format like this:

name=value;cookie_2_name=cookie_2_value

You can learn more about cookies here

Here is a function to create cookies

local function Cookie()
  local class = {
    _cookies = {}.
    addCookie = function(self, name, value)
      self._cookies[#self._cookies+1] = { name, value }
    end
  }
  local meta = { __tostring = function (t) 
    local result = ""
    for _, value in ipairs(t._cookies) do
      local k, v = value[1], value[2]
      result ..= k .. "=" .. v .. ";"
    end
    return result
 end }
 return setmetatable(class, meta)
end
2 Likes

I might be doing this wrong but I don’t know what the index/key should be called, ProxyService, which is the module I’m using, allows normal tables. Should I try normal HTTPService instead?

This is what I’m doing, authCookie is the Roblox account cookie:

local function newCookie()
	local class = {
		_cookies = {},
		addCookie = function(self, name, value)
			self._cookies[#self._cookies+1] = { name, value }
		end
	}
	local meta = { __tostring = function (t) 
		local result = ""
		for _, value in ipairs(t._cookies) do
			local k, v = value[1], value[2]
			result ..= k .. "=" .. v .. ";"
		end
		return result
	end }
	return setmetatable(class, meta)
end

local cookie = newCookie()
cookie:addCookie('.ROBLOSECURITY', authCookie)
cookie.addCookie = nil

print(proxy:Patch(
	url:format(1562331890, 1562331890),
	httpService:JSONEncode({['roleId'] = 2;}),
	Enum.HttpContentType.ApplicationJson,
	false,
	{
		cookie = tostring(cookie)
	}
))

That code errors with Header "cookie" has unallowed character "|" in value ".ROBLOSECURITY=_|WARNING:-DO-NOT-SHARE-THIS

Update:

I’m trying to use Roblox’s :RequestAsync instead and I’m getting the same error, Header "cookies" has unallowed character "|" in value ".ROBLOSECURITY=_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_. I saw on another post that you can include an escape sequence instead but what’s the sequence for it?

Update again, now it’s saying error 302 but it says it was moved to error 400?

New request:

print(proxy:Patch(
	url:format(1562331890, 1562331890),
	[[{
  		"roleId": 73924810
	}]],
	Enum.HttpContentType.ApplicationJson,
	true,
	{
		['cookies'] = '.ROBLOSECURITY='..authCookie..';'
	}
))

Screen Shot 2021-11-07 at 10.16.19 PM

Sorry if I’m a bit late with the reply but if you still haven’t figured it out you just have to remove |WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_ and the cookie will still work as it is supposed to…

1 Like