@mherod/get-cookie 4.4.1 â 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/commit-msg +0 -0
- package/.husky/pre-commit +10 -0
- package/.husky/pre-push +15 -0
- package/dist/cli.cjs +10 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +11 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/examples/README.md +40 -6
- package/examples/cli-examples.sh +0 -0
- package/examples/curl-integration.sh +195 -160
- package/examples/features-demo.sh +260 -0
- package/examples/github-auth.sh +295 -0
- package/examples/quick-start.sh +115 -0
- package/package.json +36 -45
- package/tsup.cli.ts +1 -0
- package/tsup.lib.ts +9 -1
- package/examples/chrome-cookies-demo.sh +0 -117
- package/examples/chrome-profile-demo.sh +0 -126
- package/examples/curl-demo.sh +0 -102
- package/examples/curl-with-url.sh +0 -136
- package/examples/deduplication-demo.sh +0 -110
- package/examples/final-chrome-demo.sh +0 -115
- package/examples/github-api.sh +0 -101
- package/examples/github-private-access.sh +0 -118
- package/examples/list-profiles-demo.sh +0 -120
- package/examples/proper-curl-usage.sh +0 -120
- package/examples/simple-curl.sh +0 -95
- package/examples/test-expired-filtering.sh +0 -68
- package/examples/test-github-access.sh +0 -245
- package/examples/test-github-auth-improved.sh +0 -136
- package/examples/working-curl.sh +0 -117
- package/examples/working-github-auth.sh +0 -87
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# PROPER usage of get-cookie with --url and --render for curl
|
|
4
|
-
echo "â
Correct get-cookie Usage with --url and --render"
|
|
5
|
-
echo "==================================================="
|
|
6
|
-
echo ""
|
|
7
|
-
|
|
8
|
-
# The CORRECT way to use get-cookie with curl
|
|
9
|
-
echo "đ The Right Pattern:"
|
|
10
|
-
echo "ââââââââââââââââââââ"
|
|
11
|
-
echo 'curl -H "Cookie: $(get-cookie --url <URL> --render)" <URL>'
|
|
12
|
-
echo ""
|
|
13
|
-
|
|
14
|
-
# Test 1: Simple check - what cookies do we get?
|
|
15
|
-
echo "1ī¸âŖ Checking cookies for GitHub settings:"
|
|
16
|
-
COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
|
|
17
|
-
echo " Cookie string length: $(echo "$COOKIES" | wc -c) characters"
|
|
18
|
-
echo " Number of cookies: $(echo "$COOKIES" | grep -o ';' | wc -l | xargs expr 1 +)"
|
|
19
|
-
echo ""
|
|
20
|
-
|
|
21
|
-
# Test 2: Real-world usage - accessing authenticated content
|
|
22
|
-
echo "2ī¸âŖ Testing authenticated access to GitHub:"
|
|
23
|
-
echo ""
|
|
24
|
-
|
|
25
|
-
test_url_with_cookies() {
|
|
26
|
-
local url=$1
|
|
27
|
-
local description=$2
|
|
28
|
-
|
|
29
|
-
echo "âĸ Testing: $description"
|
|
30
|
-
echo " URL: $url"
|
|
31
|
-
|
|
32
|
-
# Get cookies for this specific URL
|
|
33
|
-
local cookies=$(get-cookie --url "$url" --render 2>/dev/null)
|
|
34
|
-
|
|
35
|
-
# Make the request
|
|
36
|
-
local response=$(curl -s -L \
|
|
37
|
-
-H "Cookie: $cookies" \
|
|
38
|
-
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36" \
|
|
39
|
-
-H "Accept: text/html,application/xhtml+xml" \
|
|
40
|
-
"$url")
|
|
41
|
-
|
|
42
|
-
# Check if we're authenticated
|
|
43
|
-
if echo "$response" | grep -q "Sign in to GitHub" > /dev/null 2>&1; then
|
|
44
|
-
echo " â Not authenticated (redirected to login)"
|
|
45
|
-
elif echo "$response" | grep -q "<title>.*Settings.*</title>" > /dev/null 2>&1; then
|
|
46
|
-
echo " â
Authenticated! (reached settings page)"
|
|
47
|
-
elif echo "$response" | grep -q "Your profile" > /dev/null 2>&1; then
|
|
48
|
-
echo " â
Authenticated! (reached profile page)"
|
|
49
|
-
else
|
|
50
|
-
local title=$(echo "$response" | grep -o "<title>[^<]*</title>" | head -1)
|
|
51
|
-
echo " âšī¸ Page title: $title"
|
|
52
|
-
fi
|
|
53
|
-
echo ""
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
# Test various GitHub pages
|
|
57
|
-
test_url_with_cookies "https://github.com/settings/profile" "GitHub Settings"
|
|
58
|
-
test_url_with_cookies "https://github.com/new" "New Repository Page"
|
|
59
|
-
|
|
60
|
-
# Test 3: Working with other sites
|
|
61
|
-
echo "3ī¸âŖ Testing with other sites:"
|
|
62
|
-
echo ""
|
|
63
|
-
|
|
64
|
-
# Stack Overflow
|
|
65
|
-
SO_COOKIES=$(get-cookie --url https://stackoverflow.com/users/edit --render 2>/dev/null)
|
|
66
|
-
if [ -n "$SO_COOKIES" ]; then
|
|
67
|
-
echo "âĸ Stack Overflow:"
|
|
68
|
-
SO_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
69
|
-
-H "Cookie: $SO_COOKIES" \
|
|
70
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
71
|
-
"https://stackoverflow.com/users/edit")
|
|
72
|
-
echo " HTTP Status: $SO_STATUS"
|
|
73
|
-
[ "$SO_STATUS" = "200" ] && echo " â
Authenticated" || echo " â Not authenticated"
|
|
74
|
-
else
|
|
75
|
-
echo "âĸ Stack Overflow: No cookies found"
|
|
76
|
-
fi
|
|
77
|
-
echo ""
|
|
78
|
-
|
|
79
|
-
# Test 4: Practical one-liners
|
|
80
|
-
echo "4ī¸âŖ Practical One-Liners That Work:"
|
|
81
|
-
echo "âââââââââââââââââââââââââââââââââââ"
|
|
82
|
-
echo ""
|
|
83
|
-
echo "# Download a file with authentication:"
|
|
84
|
-
echo 'curl -O -H "Cookie: $(get-cookie --url https://example.com/file.pdf --render)" https://example.com/file.pdf'
|
|
85
|
-
echo ""
|
|
86
|
-
echo "# Check if you're logged in:"
|
|
87
|
-
echo 'curl -s -H "Cookie: $(get-cookie --url https://github.com/settings --render)" https://github.com/settings | grep -q "Sign in" && echo "Not logged in" || echo "Logged in"'
|
|
88
|
-
echo ""
|
|
89
|
-
echo "# Save response with cookies:"
|
|
90
|
-
echo 'curl -H "Cookie: $(get-cookie --url https://example.com --render)" https://example.com > page.html'
|
|
91
|
-
echo ""
|
|
92
|
-
|
|
93
|
-
# Test 5: Debugging when it doesn't work
|
|
94
|
-
echo "5ī¸âŖ Debugging Tips:"
|
|
95
|
-
echo "âââââââââââââââââ"
|
|
96
|
-
echo ""
|
|
97
|
-
echo "If authentication isn't working:"
|
|
98
|
-
echo ""
|
|
99
|
-
echo "1. Check cookie quality:"
|
|
100
|
-
echo ' get-cookie --url <URL> --output json | jq '"'"'.[] | {name, value: .value[:20], len: (.value | length)}'"'"
|
|
101
|
-
echo ""
|
|
102
|
-
echo "2. Check for expired cookies:"
|
|
103
|
-
echo ' get-cookie --url <URL> --output json | jq '"'"'.[] | select(.expiry < now | todate)'"'"
|
|
104
|
-
echo ""
|
|
105
|
-
echo "3. Try specific browser profiles:"
|
|
106
|
-
echo ' get-cookie --url <URL> --browser chrome --render'
|
|
107
|
-
echo ""
|
|
108
|
-
|
|
109
|
-
# The key insight
|
|
110
|
-
echo "â ī¸ Important Note:"
|
|
111
|
-
echo "ââââââââââââââââââ"
|
|
112
|
-
echo "Some sites (like GitHub) may have multiple session cookies across different"
|
|
113
|
-
echo "browser profiles. The --url flag gets ALL matching cookies, which may include"
|
|
114
|
-
echo "invalid ones. For production use, you might need to:"
|
|
115
|
-
echo ""
|
|
116
|
-
echo "1. Use --browser to target a specific browser"
|
|
117
|
-
echo "2. Use --output json and filter for valid cookies"
|
|
118
|
-
echo "3. Check cookie expiration dates"
|
|
119
|
-
echo ""
|
|
120
|
-
echo "â
The CLI is working correctly - it's faithfully extracting what the browsers have stored!"
|
package/examples/simple-curl.sh
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Simple and practical get-cookie + curl integration using --render
|
|
4
|
-
echo "đĒ get-cookie + curl Integration (using --render)"
|
|
5
|
-
echo "=================================================="
|
|
6
|
-
|
|
7
|
-
# The --render flag outputs cookies in the perfect format for curl: name=value
|
|
8
|
-
|
|
9
|
-
# Example 1: Single cookie with curl
|
|
10
|
-
echo -e "\n1ī¸âŖ Getting GitHub user session cookie..."
|
|
11
|
-
USER_SESSION=$(get-cookie user_session github.com --render 2>/dev/null)
|
|
12
|
-
|
|
13
|
-
if [ -n "$USER_SESSION" ]; then
|
|
14
|
-
echo " â
Got cookie: ${USER_SESSION:0:30}..."
|
|
15
|
-
|
|
16
|
-
# Use directly with curl
|
|
17
|
-
echo -e "\n2ī¸âŖ Using cookie with GitHub API..."
|
|
18
|
-
curl -s \
|
|
19
|
-
-H "Cookie: $USER_SESSION" \
|
|
20
|
-
-H "User-Agent: get-cookie-demo" \
|
|
21
|
-
"https://api.github.com/user" | jq -r '.login' | while read LOGIN; do
|
|
22
|
-
if [ -n "$LOGIN" ] && [ "$LOGIN" != "null" ]; then
|
|
23
|
-
echo " â
Authenticated as: @$LOGIN"
|
|
24
|
-
else
|
|
25
|
-
echo " â ī¸ Cookie didn't work for API (may need different cookie)"
|
|
26
|
-
fi
|
|
27
|
-
done
|
|
28
|
-
else
|
|
29
|
-
echo " â No user_session cookie found"
|
|
30
|
-
fi
|
|
31
|
-
|
|
32
|
-
# Example 2: Multiple cookies (semicolon separated)
|
|
33
|
-
echo -e "\n3ī¸âŖ Getting multiple GitHub cookies..."
|
|
34
|
-
COOKIES=""
|
|
35
|
-
for cookie_name in "user_session" "dotcom_user" "__Host-user_session_same_site" "_gh_sess"; do
|
|
36
|
-
COOKIE=$(get-cookie "$cookie_name" github.com --render 2>/dev/null | head -1)
|
|
37
|
-
if [ -n "$COOKIE" ]; then
|
|
38
|
-
[ -n "$COOKIES" ] && COOKIES="$COOKIES; "
|
|
39
|
-
COOKIES="$COOKIES$COOKIE"
|
|
40
|
-
echo " â
Added: ${cookie_name}"
|
|
41
|
-
fi
|
|
42
|
-
done
|
|
43
|
-
|
|
44
|
-
if [ -n "$COOKIES" ]; then
|
|
45
|
-
echo -e "\n4ī¸âŖ Testing authenticated page access..."
|
|
46
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
47
|
-
-H "Cookie: $COOKIES" \
|
|
48
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
49
|
-
"https://github.com/settings/profile")
|
|
50
|
-
|
|
51
|
-
echo " HTTP Response: $HTTP_CODE"
|
|
52
|
-
[ "$HTTP_CODE" = "200" ] && echo " â
Successfully accessed protected page!"
|
|
53
|
-
fi
|
|
54
|
-
|
|
55
|
-
# Example 3: Direct one-liner for API calls
|
|
56
|
-
echo -e "\n5ī¸âŖ One-liner examples:"
|
|
57
|
-
echo "ââââââââââââââââââââ"
|
|
58
|
-
echo ""
|
|
59
|
-
echo "# Get user info with single command:"
|
|
60
|
-
echo 'curl -s -H "Cookie: $(get-cookie user_session github.com --render)" https://api.github.com/user | jq .login'
|
|
61
|
-
echo ""
|
|
62
|
-
|
|
63
|
-
echo "# Download file with authentication:"
|
|
64
|
-
echo 'curl -H "Cookie: $(get-cookie user_session github.com --render)" -o file.zip https://github.com/user/repo/archive/main.zip'
|
|
65
|
-
echo ""
|
|
66
|
-
|
|
67
|
-
echo "# Using with wget:"
|
|
68
|
-
echo 'wget --header="Cookie: $(get-cookie user_session github.com --render)" https://github.com/user/private-repo'
|
|
69
|
-
echo ""
|
|
70
|
-
|
|
71
|
-
echo "# Using with HTTPie:"
|
|
72
|
-
echo 'http https://api.github.com/user "Cookie:$(get-cookie user_session github.com --render)"'
|
|
73
|
-
|
|
74
|
-
# Example 4: Practical use case - checking star count
|
|
75
|
-
echo -e "\n6ī¸âŖ Practical example: Check if you've starred a repo..."
|
|
76
|
-
COOKIE=$(get-cookie user_session github.com --render 2>/dev/null | head -1)
|
|
77
|
-
if [ -n "$COOKIE" ]; then
|
|
78
|
-
STARRED=$(curl -s -H "Cookie: $COOKIE" \
|
|
79
|
-
-H "User-Agent: get-cookie-demo" \
|
|
80
|
-
"https://api.github.com/user/starred/mherod/get-cookie" \
|
|
81
|
-
-w "%{http_code}" -o /dev/null)
|
|
82
|
-
|
|
83
|
-
if [ "$STARRED" = "204" ]; then
|
|
84
|
-
echo " â You've starred mherod/get-cookie!"
|
|
85
|
-
elif [ "$STARRED" = "404" ]; then
|
|
86
|
-
echo " â You haven't starred mherod/get-cookie yet"
|
|
87
|
-
else
|
|
88
|
-
echo " â ī¸ Couldn't check star status (HTTP $STARRED)"
|
|
89
|
-
fi
|
|
90
|
-
fi
|
|
91
|
-
|
|
92
|
-
echo -e "\nâ
Demo complete!"
|
|
93
|
-
echo ""
|
|
94
|
-
echo "đĄ TIP: The --render flag outputs cookies in 'name=value' format,"
|
|
95
|
-
echo " perfect for direct use with curl's Cookie header!"
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Test the expired cookie filtering feature
|
|
4
|
-
echo "đ Testing Expired Cookie Filtering"
|
|
5
|
-
echo "===================================="
|
|
6
|
-
echo ""
|
|
7
|
-
|
|
8
|
-
# Test 1: Check default behavior (should filter expired)
|
|
9
|
-
echo "1ī¸âŖ Default behavior (filters expired cookies):"
|
|
10
|
-
echo "âââââââââââââââââââââââââââââââââââââââââââââ"
|
|
11
|
-
DEFAULT_COUNT=$(get-cookie --url https://github.com --output json 2>/dev/null | jq 'length')
|
|
12
|
-
echo " Cookies returned: $DEFAULT_COUNT"
|
|
13
|
-
echo ""
|
|
14
|
-
|
|
15
|
-
# Test 2: Check with --include-expired flag
|
|
16
|
-
echo "2ī¸âŖ With --include-expired flag:"
|
|
17
|
-
echo "ââââââââââââââââââââââââââââââââ"
|
|
18
|
-
WITH_EXPIRED_COUNT=$(get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq 'length')
|
|
19
|
-
echo " Cookies returned: $WITH_EXPIRED_COUNT"
|
|
20
|
-
echo ""
|
|
21
|
-
|
|
22
|
-
# Test 3: Compare the difference
|
|
23
|
-
echo "3ī¸âŖ Analysis:"
|
|
24
|
-
echo "âââââââââââ"
|
|
25
|
-
if [ "$WITH_EXPIRED_COUNT" -gt "$DEFAULT_COUNT" ]; then
|
|
26
|
-
DIFF=$((WITH_EXPIRED_COUNT - DEFAULT_COUNT))
|
|
27
|
-
echo " â
Filtering is working! Removed $DIFF expired cookies"
|
|
28
|
-
else
|
|
29
|
-
echo " âšī¸ No expired cookies found (or same count)"
|
|
30
|
-
fi
|
|
31
|
-
echo ""
|
|
32
|
-
|
|
33
|
-
# Test 4: Show example cookies with expiry info
|
|
34
|
-
echo "4ī¸âŖ Sample cookies with expiry info:"
|
|
35
|
-
echo "ââââââââââââââââââââââââââââââââââ"
|
|
36
|
-
echo "Default (non-expired only):"
|
|
37
|
-
get-cookie --url https://github.com --output json 2>/dev/null | jq -r '.[:3] | .[] | " âĸ \(.name): expires \(if .expiry then (.expiry | todate) else "session" end)"'
|
|
38
|
-
echo ""
|
|
39
|
-
|
|
40
|
-
echo "With expired included:"
|
|
41
|
-
get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq -r '.[:3] | .[] | " âĸ \(.name): expires \(if .expiry then (.expiry | todate) else "session" end)"'
|
|
42
|
-
echo ""
|
|
43
|
-
|
|
44
|
-
# Test 5: Practical curl test
|
|
45
|
-
echo "5ī¸âŖ Practical test with curl:"
|
|
46
|
-
echo "ââââââââââââââââââââââââââ"
|
|
47
|
-
echo "Testing GitHub authentication with filtered cookies..."
|
|
48
|
-
COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
|
|
49
|
-
RESPONSE=$(curl -s -L \
|
|
50
|
-
-H "Cookie: $COOKIES" \
|
|
51
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
52
|
-
"https://github.com/settings/profile" | grep -o "<title>[^<]*</title>" | head -1)
|
|
53
|
-
|
|
54
|
-
if echo "$RESPONSE" | grep -q "Your profile"; then
|
|
55
|
-
echo "â
Authentication successful with filtered cookies!"
|
|
56
|
-
elif echo "$RESPONSE" | grep -q "Sign in"; then
|
|
57
|
-
echo "â Authentication failed (redirected to sign in)"
|
|
58
|
-
else
|
|
59
|
-
echo "âšī¸ Response: $RESPONSE"
|
|
60
|
-
fi
|
|
61
|
-
echo ""
|
|
62
|
-
|
|
63
|
-
echo "đĄ Summary:"
|
|
64
|
-
echo "âââââââââ"
|
|
65
|
-
echo "The --include-expired flag controls whether expired cookies are included."
|
|
66
|
-
echo "By default, expired cookies are filtered out for better authentication success."
|
|
67
|
-
echo ""
|
|
68
|
-
echo "â
Feature is working as expected!"
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Test what GitHub content we can actually access with browser cookies
|
|
4
|
-
echo "đ Testing GitHub Private Access with Browser Cookies"
|
|
5
|
-
echo "====================================================="
|
|
6
|
-
echo ""
|
|
7
|
-
|
|
8
|
-
# Get all GitHub cookies
|
|
9
|
-
COOKIES=$(get-cookie --url https://github.com --render 2>/dev/null)
|
|
10
|
-
|
|
11
|
-
if [ -z "$COOKIES" ]; then
|
|
12
|
-
echo "â No GitHub cookies found. Please log into GitHub in your browser."
|
|
13
|
-
exit 1
|
|
14
|
-
fi
|
|
15
|
-
|
|
16
|
-
echo "â
Found GitHub cookies ($(echo "$COOKIES" | grep -o ';' | wc -l | xargs expr 1 +) cookies)"
|
|
17
|
-
echo ""
|
|
18
|
-
|
|
19
|
-
# Extract username from cookies
|
|
20
|
-
USERNAME=$(get-cookie dotcom_user github.com --render 2>/dev/null | cut -d'=' -f2 | cut -d';' -f1)
|
|
21
|
-
if [ -n "$USERNAME" ]; then
|
|
22
|
-
echo "đ¤ Detected GitHub username: $USERNAME"
|
|
23
|
-
else
|
|
24
|
-
echo "â ī¸ Could not detect username from cookies"
|
|
25
|
-
USERNAME="mherod" # fallback for testing
|
|
26
|
-
fi
|
|
27
|
-
|
|
28
|
-
echo ""
|
|
29
|
-
echo "Testing various GitHub endpoints..."
|
|
30
|
-
echo "ââââââââââââââââââââââââââââââââââââ"
|
|
31
|
-
|
|
32
|
-
# Function to test GitHub endpoints
|
|
33
|
-
test_endpoint() {
|
|
34
|
-
local name=$1
|
|
35
|
-
local url=$2
|
|
36
|
-
local check_string=$3
|
|
37
|
-
|
|
38
|
-
echo -n "âĸ $name: "
|
|
39
|
-
|
|
40
|
-
RESPONSE=$(curl -s -L \
|
|
41
|
-
-H "Cookie: $COOKIES" \
|
|
42
|
-
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
|
|
43
|
-
-H "Accept: text/html,application/xhtml+xml" \
|
|
44
|
-
"$url")
|
|
45
|
-
|
|
46
|
-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
47
|
-
-H "Cookie: $COOKIES" \
|
|
48
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
49
|
-
"$url")
|
|
50
|
-
|
|
51
|
-
if echo "$RESPONSE" | grep -q "$check_string" > /dev/null 2>&1; then
|
|
52
|
-
echo "â
Authenticated (HTTP $HTTP_CODE)"
|
|
53
|
-
return 0
|
|
54
|
-
elif [ "$HTTP_CODE" = "200" ]; then
|
|
55
|
-
echo "â ī¸ Accessible but not authenticated (HTTP 200)"
|
|
56
|
-
return 1
|
|
57
|
-
elif [ "$HTTP_CODE" = "404" ]; then
|
|
58
|
-
echo "â Not found (HTTP 404)"
|
|
59
|
-
return 1
|
|
60
|
-
elif [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "301" ]; then
|
|
61
|
-
echo "đ Redirected - not authenticated (HTTP $HTTP_CODE)"
|
|
62
|
-
return 1
|
|
63
|
-
else
|
|
64
|
-
echo "â Failed (HTTP $HTTP_CODE)"
|
|
65
|
-
return 1
|
|
66
|
-
fi
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
# Test public profile (should work either way)
|
|
70
|
-
test_endpoint "Public profile" \
|
|
71
|
-
"https://github.com/$USERNAME" \
|
|
72
|
-
"Follow"
|
|
73
|
-
|
|
74
|
-
# Test settings page (requires authentication)
|
|
75
|
-
test_endpoint "Settings page" \
|
|
76
|
-
"https://github.com/settings/profile" \
|
|
77
|
-
"Public profile"
|
|
78
|
-
|
|
79
|
-
# Test notifications (requires authentication)
|
|
80
|
-
test_endpoint "Notifications" \
|
|
81
|
-
"https://github.com/notifications" \
|
|
82
|
-
"notifications"
|
|
83
|
-
|
|
84
|
-
# Test security settings (requires authentication)
|
|
85
|
-
test_endpoint "Security settings" \
|
|
86
|
-
"https://github.com/settings/security" \
|
|
87
|
-
"Two-factor"
|
|
88
|
-
|
|
89
|
-
# Test SSH keys page (requires authentication)
|
|
90
|
-
test_endpoint "SSH keys" \
|
|
91
|
-
"https://github.com/settings/keys" \
|
|
92
|
-
"SSH keys"
|
|
93
|
-
|
|
94
|
-
echo ""
|
|
95
|
-
echo "Testing repository access..."
|
|
96
|
-
echo "ââââââââââââââââââââââââââââ"
|
|
97
|
-
|
|
98
|
-
# Test accessing this repository (get-cookie)
|
|
99
|
-
echo -n "âĸ get-cookie repo: "
|
|
100
|
-
REPO_RESPONSE=$(curl -s -L \
|
|
101
|
-
-H "Cookie: $COOKIES" \
|
|
102
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
103
|
-
"https://github.com/$USERNAME/get-cookie")
|
|
104
|
-
|
|
105
|
-
if echo "$REPO_RESPONSE" | grep -q "Code" > /dev/null 2>&1; then
|
|
106
|
-
echo "â
Can access"
|
|
107
|
-
|
|
108
|
-
# Check if we can see the clone button (indicates authenticated access)
|
|
109
|
-
if echo "$REPO_RESPONSE" | grep -q "Use Git or checkout with SVN" > /dev/null 2>&1; then
|
|
110
|
-
echo " ââ â
Authenticated view (can see clone options)"
|
|
111
|
-
fi
|
|
112
|
-
else
|
|
113
|
-
echo "â Cannot access"
|
|
114
|
-
fi
|
|
115
|
-
|
|
116
|
-
# Test creating a new repository page (requires authentication)
|
|
117
|
-
echo -n "âĸ New repo page: "
|
|
118
|
-
NEW_REPO_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
119
|
-
-H "Cookie: $COOKIES" \
|
|
120
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
121
|
-
"https://github.com/new")
|
|
122
|
-
|
|
123
|
-
if [ "$NEW_REPO_CODE" = "200" ]; then
|
|
124
|
-
echo "â
Can access (authenticated)"
|
|
125
|
-
else
|
|
126
|
-
echo "â Cannot access (HTTP $NEW_REPO_CODE)"
|
|
127
|
-
fi
|
|
128
|
-
|
|
129
|
-
echo ""
|
|
130
|
-
echo "Testing private repository detection..."
|
|
131
|
-
echo "âââââââââââââââââââââââââââââââââââââââ"
|
|
132
|
-
|
|
133
|
-
# Try to list repositories including private ones
|
|
134
|
-
echo "Attempting to fetch repository list..."
|
|
135
|
-
|
|
136
|
-
REPOS_PAGE=$(curl -s -L \
|
|
137
|
-
-H "Cookie: $COOKIES" \
|
|
138
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
139
|
-
"https://github.com/$USERNAME?tab=repositories")
|
|
140
|
-
|
|
141
|
-
# Count repositories visible
|
|
142
|
-
PUBLIC_COUNT=$(echo "$REPOS_PAGE" | grep -o 'itemprop="name codeRepository"' | wc -l | xargs)
|
|
143
|
-
echo "âĸ Repositories visible: $PUBLIC_COUNT"
|
|
144
|
-
|
|
145
|
-
# Check if we can see private repo indicators
|
|
146
|
-
if echo "$REPOS_PAGE" | grep -q "Private" > /dev/null 2>&1; then
|
|
147
|
-
echo "âĸ â
Can see private repository badges"
|
|
148
|
-
PRIVATE_COUNT=$(echo "$REPOS_PAGE" | grep -o '>Private<' | wc -l | xargs)
|
|
149
|
-
echo "âĸ Private repositories visible: $PRIVATE_COUNT"
|
|
150
|
-
else
|
|
151
|
-
echo "âĸ â ī¸ No private repository badges found (may not have any or not authenticated)"
|
|
152
|
-
fi
|
|
153
|
-
|
|
154
|
-
echo ""
|
|
155
|
-
echo "Testing specific private repository (if you have one)..."
|
|
156
|
-
echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââââââ"
|
|
157
|
-
|
|
158
|
-
# Function to test a specific private repo
|
|
159
|
-
test_private_repo() {
|
|
160
|
-
local repo_name=$1
|
|
161
|
-
echo -n "âĸ Testing $USERNAME/$repo_name: "
|
|
162
|
-
|
|
163
|
-
REPO_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
164
|
-
-H "Cookie: $COOKIES" \
|
|
165
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
166
|
-
"https://github.com/$USERNAME/$repo_name")
|
|
167
|
-
|
|
168
|
-
if [ "$REPO_CODE" = "200" ]; then
|
|
169
|
-
echo "â
Accessible (HTTP 200)"
|
|
170
|
-
|
|
171
|
-
# Try to get file list
|
|
172
|
-
FILE_LIST=$(curl -s \
|
|
173
|
-
-H "Cookie: $COOKIES" \
|
|
174
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
175
|
-
"https://github.com/$USERNAME/$repo_name" | grep -o 'js-navigation-open Link--primary' | wc -l | xargs)
|
|
176
|
-
|
|
177
|
-
if [ "$FILE_LIST" -gt 0 ]; then
|
|
178
|
-
echo " ââ â
Can see $FILE_LIST files/folders"
|
|
179
|
-
fi
|
|
180
|
-
return 0
|
|
181
|
-
elif [ "$REPO_CODE" = "404" ]; then
|
|
182
|
-
echo "â Not found or no access (HTTP 404)"
|
|
183
|
-
return 1
|
|
184
|
-
else
|
|
185
|
-
echo "â Cannot access (HTTP $REPO_CODE)"
|
|
186
|
-
return 1
|
|
187
|
-
fi
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
# Test some common private repo names (you can modify these)
|
|
191
|
-
echo "Testing potential private repositories..."
|
|
192
|
-
for repo in "private" "personal" "dotfiles" "config" "secrets" "private-notes"; do
|
|
193
|
-
test_private_repo "$repo"
|
|
194
|
-
done
|
|
195
|
-
|
|
196
|
-
echo ""
|
|
197
|
-
echo "Testing raw file access..."
|
|
198
|
-
echo "âââââââââââââââââââââ"
|
|
199
|
-
|
|
200
|
-
# Try to access a raw file from a public repo (should work)
|
|
201
|
-
echo -n "âĸ Public repo raw file: "
|
|
202
|
-
RAW_PUBLIC=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
203
|
-
-H "Cookie: $COOKIES" \
|
|
204
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
205
|
-
"https://raw.githubusercontent.com/$USERNAME/get-cookie/main/README.md")
|
|
206
|
-
|
|
207
|
-
if [ "$RAW_PUBLIC" = "200" ]; then
|
|
208
|
-
echo "â
Can access"
|
|
209
|
-
else
|
|
210
|
-
echo "â Cannot access (HTTP $RAW_PUBLIC)"
|
|
211
|
-
fi
|
|
212
|
-
|
|
213
|
-
echo ""
|
|
214
|
-
echo "Advanced: Testing GitHub's auth state..."
|
|
215
|
-
echo "ââââââââââââââââââââââââââââââââââââââââ"
|
|
216
|
-
|
|
217
|
-
# Check the actual auth state from GitHub's perspective
|
|
218
|
-
AUTH_CHECK=$(curl -s \
|
|
219
|
-
-H "Cookie: $COOKIES" \
|
|
220
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
221
|
-
-H "Accept: application/json" \
|
|
222
|
-
"https://github.com/users/$USERNAME/hovercard" | jq -r '.message // "authenticated"')
|
|
223
|
-
|
|
224
|
-
if [ "$AUTH_CHECK" = "authenticated" ]; then
|
|
225
|
-
echo "â
GitHub recognizes our session as authenticated"
|
|
226
|
-
else
|
|
227
|
-
echo "â ī¸ GitHub response: $AUTH_CHECK"
|
|
228
|
-
fi
|
|
229
|
-
|
|
230
|
-
echo ""
|
|
231
|
-
echo "Summary"
|
|
232
|
-
echo "======="
|
|
233
|
-
echo ""
|
|
234
|
-
echo "đ What we learned:"
|
|
235
|
-
echo "âĸ Browser cookies work for GitHub web pages (not API)"
|
|
236
|
-
echo "âĸ Can access authenticated pages like settings"
|
|
237
|
-
echo "âĸ Can view private repositories through the web interface"
|
|
238
|
-
echo "âĸ Cannot use these cookies for the REST API (needs tokens)"
|
|
239
|
-
echo ""
|
|
240
|
-
echo "đĄ To actually work with private repos via CLI:"
|
|
241
|
-
echo "âĸ Use GitHub CLI: gh auth login"
|
|
242
|
-
echo "âĸ Or create a Personal Access Token"
|
|
243
|
-
echo "âĸ Browser cookies are mainly useful for web scraping"
|
|
244
|
-
echo ""
|
|
245
|
-
echo "â
Test complete!"
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Test GitHub authentication with improved expired cookie filtering
|
|
4
|
-
echo "đ Testing GitHub Authentication with Improved Cookie Filtering"
|
|
5
|
-
echo "=============================================================="
|
|
6
|
-
echo ""
|
|
7
|
-
|
|
8
|
-
# Method 1: Using --url and --render (the recommended pattern)
|
|
9
|
-
echo "Method 1: Using --url and --render (default filtering)"
|
|
10
|
-
echo "ââââââââââââââââââââââââââââââââââââââââââââââââââââââ"
|
|
11
|
-
|
|
12
|
-
# Get cookies for GitHub settings
|
|
13
|
-
COOKIES=$(get-cookie --url https://github.com/settings/profile --render 2>/dev/null)
|
|
14
|
-
echo "Cookie string length: $(echo "$COOKIES" | wc -c) characters"
|
|
15
|
-
|
|
16
|
-
# Test authentication
|
|
17
|
-
echo -n "Testing authentication: "
|
|
18
|
-
RESPONSE=$(curl -s -L \
|
|
19
|
-
-H "Cookie: $COOKIES" \
|
|
20
|
-
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" \
|
|
21
|
-
-H "Accept: text/html,application/xhtml+xml" \
|
|
22
|
-
"https://github.com/settings/profile")
|
|
23
|
-
|
|
24
|
-
if echo "$RESPONSE" | grep -q "Sign in to GitHub"; then
|
|
25
|
-
echo "â Not authenticated (redirected to login)"
|
|
26
|
-
elif echo "$RESPONSE" | grep -q "Your profile"; then
|
|
27
|
-
echo "â
Authenticated! (settings page accessed)"
|
|
28
|
-
else
|
|
29
|
-
TITLE=$(echo "$RESPONSE" | grep -o "<title>[^<]*</title>" | head -1)
|
|
30
|
-
echo "âšī¸ Page title: $TITLE"
|
|
31
|
-
fi
|
|
32
|
-
echo ""
|
|
33
|
-
|
|
34
|
-
# Method 2: With --include-expired to see the difference
|
|
35
|
-
echo "Method 2: With --include-expired flag"
|
|
36
|
-
echo "âââââââââââââââââââââââââââââââââââââ"
|
|
37
|
-
|
|
38
|
-
COOKIES_WITH_EXPIRED=$(get-cookie --url https://github.com/settings/profile --render --include-expired 2>/dev/null)
|
|
39
|
-
echo "Cookie string length: $(echo "$COOKIES_WITH_EXPIRED" | wc -c) characters"
|
|
40
|
-
|
|
41
|
-
# Compare cookie counts
|
|
42
|
-
DEFAULT_COUNT=$(get-cookie --url https://github.com --output json 2>/dev/null | jq 'length')
|
|
43
|
-
EXPIRED_COUNT=$(get-cookie --url https://github.com --output json --include-expired 2>/dev/null | jq 'length')
|
|
44
|
-
|
|
45
|
-
echo "Cookies comparison:"
|
|
46
|
-
echo " âĸ Without --include-expired: $DEFAULT_COUNT cookies"
|
|
47
|
-
echo " âĸ With --include-expired: $EXPIRED_COUNT cookies"
|
|
48
|
-
|
|
49
|
-
if [ "$EXPIRED_COUNT" -gt "$DEFAULT_COUNT" ]; then
|
|
50
|
-
DIFF=$((EXPIRED_COUNT - DEFAULT_COUNT))
|
|
51
|
-
echo " âĸ â
Filtered out $DIFF expired cookies"
|
|
52
|
-
else
|
|
53
|
-
echo " âĸ âšī¸ No expired cookies to filter (all cookies are valid)"
|
|
54
|
-
fi
|
|
55
|
-
echo ""
|
|
56
|
-
|
|
57
|
-
# Method 3: Smart filtering for valid session cookies
|
|
58
|
-
echo "Method 3: JSON filtering for valid cookies"
|
|
59
|
-
echo "ââââââââââââââââââââââââââââââââââââââââââ"
|
|
60
|
-
|
|
61
|
-
# Get valid session cookie (filter by length and expiry)
|
|
62
|
-
VALID_SESSION=$(get-cookie --url https://github.com --output json 2>/dev/null | \
|
|
63
|
-
jq -r '.[] | select(.name == "user_session" and (.value | length) > 20) | .value' | \
|
|
64
|
-
head -1)
|
|
65
|
-
|
|
66
|
-
if [ -n "$VALID_SESSION" ]; then
|
|
67
|
-
echo "â
Found valid session cookie: ${VALID_SESSION:0:20}... (${#VALID_SESSION} chars)"
|
|
68
|
-
|
|
69
|
-
# Build cookie header
|
|
70
|
-
COOKIE_HEADER="user_session=$VALID_SESSION; __Host-user_session_same_site=$VALID_SESSION"
|
|
71
|
-
|
|
72
|
-
# Test authentication
|
|
73
|
-
echo -n "Testing with filtered session: "
|
|
74
|
-
AUTH_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
75
|
-
-H "Cookie: $COOKIE_HEADER" \
|
|
76
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
77
|
-
"https://github.com/settings/profile")
|
|
78
|
-
|
|
79
|
-
if [ "$AUTH_CODE" = "200" ]; then
|
|
80
|
-
echo "â
Authenticated (HTTP 200)"
|
|
81
|
-
else
|
|
82
|
-
echo "â Not authenticated (HTTP $AUTH_CODE)"
|
|
83
|
-
fi
|
|
84
|
-
else
|
|
85
|
-
echo "â No valid session cookie found"
|
|
86
|
-
fi
|
|
87
|
-
echo ""
|
|
88
|
-
|
|
89
|
-
# Final test: Access private content
|
|
90
|
-
echo "Final Test: Accessing Private Repository List"
|
|
91
|
-
echo "âââââââââââââââââââââââââââââââââââââââââââââ"
|
|
92
|
-
|
|
93
|
-
# Try to get username from cookies
|
|
94
|
-
USERNAME=$(get-cookie dotcom_user github.com --output json 2>/dev/null | jq -r '.[0].value' | cut -d';' -f1)
|
|
95
|
-
|
|
96
|
-
if [ -n "$USERNAME" ]; then
|
|
97
|
-
echo "Username detected: $USERNAME"
|
|
98
|
-
|
|
99
|
-
# Get repository list with authentication
|
|
100
|
-
REPOS_HTML=$(curl -s -L \
|
|
101
|
-
-H "Cookie: $(get-cookie --url https://github.com/$USERNAME --render)" \
|
|
102
|
-
-H "User-Agent: Mozilla/5.0" \
|
|
103
|
-
"https://github.com/$USERNAME?tab=repositories")
|
|
104
|
-
|
|
105
|
-
# Count visible repositories
|
|
106
|
-
PUBLIC_COUNT=$(echo "$REPOS_HTML" | grep -o '>Public<' | wc -l | xargs)
|
|
107
|
-
PRIVATE_COUNT=$(echo "$REPOS_HTML" | grep -o '>Private<' | wc -l | xargs)
|
|
108
|
-
|
|
109
|
-
echo "Repository visibility:"
|
|
110
|
-
echo " âĸ Public repositories: $PUBLIC_COUNT"
|
|
111
|
-
echo " âĸ Private repositories: $PRIVATE_COUNT"
|
|
112
|
-
|
|
113
|
-
if [ "$PRIVATE_COUNT" -gt 0 ]; then
|
|
114
|
-
echo " âĸ â
Can see private repositories!"
|
|
115
|
-
else
|
|
116
|
-
echo " âĸ â ī¸ No private repositories visible"
|
|
117
|
-
fi
|
|
118
|
-
else
|
|
119
|
-
echo "â Could not detect username from cookies"
|
|
120
|
-
fi
|
|
121
|
-
echo ""
|
|
122
|
-
|
|
123
|
-
echo "đĄ Summary:"
|
|
124
|
-
echo "âââââââââ"
|
|
125
|
-
echo "âĸ Default behavior filters expired cookies for better success"
|
|
126
|
-
echo "âĸ Use --include-expired to include all cookies (debugging)"
|
|
127
|
-
echo "âĸ For best results: get-cookie --url <URL> --render"
|
|
128
|
-
echo "âĸ Some browsers may store invalid cookies that need filtering"
|
|
129
|
-
echo ""
|
|
130
|
-
|
|
131
|
-
# Check if the feature is making a difference
|
|
132
|
-
if [ "$DEFAULT_COUNT" -eq "$EXPIRED_COUNT" ]; then
|
|
133
|
-
echo "âšī¸ Note: Currently all cookies are valid (no expired cookies found)"
|
|
134
|
-
else
|
|
135
|
-
echo "â
Expired cookie filtering is improving authentication!"
|
|
136
|
-
fi
|