internal-api-cookie-auth
Skill1 starsChanged 17 days agoMITView on GitHub
Handle Cookie (CAS) authentication for internal HTTPS API calls without asking users to manually paste session Cookies. Use this skill whenever a script, service, or API debugging task lacks a Cookie, reports a session expiry, redirects to cas.baijia.com or test-cas.baijia.com, returns HTTP 401, returns a CAS-style JSON code 700, or may have failed because of authentication. Also use it when the user pastes a browser "copy as cURL" command for an internal host (gaotu100.com, baijia.com): it teaches how to wrap the request in any form (command, bash, or Python) with a fresh Cookie and minimal headers instead of the pasted Cookie, and to confirm before replaying side-effecting POST/PUT/PATCH/DELETE calls. Use it before hardcoding a Cookie. Only probe an unknown host after the user authorizes a real read-only test; treat HTTP 403 as a possible authorization failure, not evidence that a Cookie refresh will help.
In this repository10 other files it gives its agents.
- case-design-strategy-skillSkill
- case-lite-larkSkill
- case-liteSkill
- case-reorganizeSkill
- context-resilient-taskSkill
- cross-agent-reviewSkill
- deep-task-preflightSkill
- dify-dsl-generatorSkill
- repository-code-styleSkill
- whitebox-op-comboSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 4 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 49
Instead, request only the identical HTTPS URL (including query) and store only its Cookies.
- Very specific: line 72
When the user authorizes a real read-only test, attempt it without a Cookie.
- Very specific: line 92
Run the bundled script from the installed Skill directory only after the user has authorized the authentication attempt.
- Very specific: line 118
Ask for or locate a safe read-only probe URL first.
- Distinctive: line 140
When the user pastes a browser "copy as cURL" command, do not hardcode its Cookie.
- Very specific: line 156
Keep the wrapper minimal. Forward only what the endpoint needs — usually just the Cookie plus content-type when there is a JSON body.
- Very specific: line 190
Do not add a --password option.
- Distinctive: line 192
Do not put usernames, passwords, Cookie values, or request headers containing Cookies in source control, terminal output, errors, tests, or …
- Distinctive: line 198
Do not persist Cookies beyond the requested operation unless the user has explicitly asked for a protected local cache and its expiry …
- Distinctive: line 215
Do not reuse, hardcode, or commit a pasted or browser-exported Cookie — it expires and leaks the session.
- Very specific: line 217
Do not guess a CAS service URL from a bare 401, an HTML login page, or an untrusted redirect / code/errorCode:700 data.
- Very specific: line 220
Do not replay a POST/PUT/PATCH/DELETE without explicit user confirmation, and never auto-retry a side-effecting call.
- Very specific: line 222
Do not forward browser-noise headers by default.
- Very specific: line 224
Do not add a --password flag or place credentials or Cookies in argv, URLs, logs, errors, tests, or chat.
- Very specific: line 226
Do not loop-refresh the session on a 403.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Internal API Cookie Authentication
Purpose
Obtain a short-lived Cookie through the bundled, self-contained CAS login script
(scripts/cas_login.py, Python standard library only — no Node.js, no external
checkout, no hardcoded path) only when it is needed, then pass it to the target
script through a protected file or process environment. This avoids copying
session Cookies into commands, source files, or chat output while preserving the
user's existing authentication choices.
Scope And Trust Boundary
These HTTPS hosts have built-in CAS service configuration:
internal-ad.gaotu100.comandtest-internal-ad.gaotu100.comathena.baijia.comandtest-athena.baijia.comdis.baijia.comandtest-dis.baijia.com
Other internal HTTPS hosts are supported only by one of these evidence-based paths:
- The user or repository configuration provides an explicit
--cas-service-url(HTTPS ordinarily; the narrow HTTP exception below is enforced by the script). - A user-authorized, read-only
--discover-casprobe gets back a trusted-CAS signal — either a302/303/307/308redirect, or (the common gaotu case) a JSON body{"code":700,"data":"<cas login url>"}or{"errorCode":700,"data":"<cas login url>"}— whose CAS host matches the target environment and carries one HTTPSserviceparameter. The only exception is an explicitly provided same-host, same-port, same-path HTTPservicefor an HTTPS target. Preserve that originalservicein the CAS request; when CAS reaches it with a ticket, do not request the HTTP callback. Instead, request only the identical HTTPS URL (including query) and store only its Cookies. Reject cross-host, changed-port/path/query, non-HTTPS, or any later HTTP redirect. The no-Cookie discovery probe cannot manufacture a ticket, so it is not evidence for this exception.
The probe sends no Cookie and follows no redirect. It accepts a service only
from https://cas.baijia.com/cas/login for production targets or
https://test-cas.baijia.com/cas/login for test- targets, whether that login
URL arrives as a redirect Location header or as the data field of a
code/errorCode:700 body. A signal pointing at any other login host is not evidence that
this Skill may send credentials there.
Built-in service entries (Internal AD / UOS, Athena, Compass) are resolved by
scripts/cas_login.py with no configuration. test- hosts default the password
to the username; production hosts require SITE_PASSWORD.
Authentication Decision
- Reuse an explicit Cookie, configured Cookie file, or the target program's documented Cookie environment variable first.
- During dry-run, mock, unit-test, or static-development work, do not issue a network probe just to discover authentication. Preserve the script's normal dry-run boundary.
- When the user authorizes a real read-only test, attempt it without a Cookie.
The service URL can be discovered automatically from either a
302/303/307/308redirect to trusted CAS, or a JSON body{"code":700,"data":"<cas login url>"}/{"errorCode":700,"data":"<cas login url>"}returned with HTTP200/401. Most gaotu internal APIs use the JSON form: thedatafield is the fullhttps://<cas-host>/cas/login?service=...URL, and theserviceparameter is the value the cookie tool needs. Passing the complete trusted CAS login URL to--cas-service-urlis also accepted and unwrapped. A bare HTTP401with no body, or acode/errorCode:700whosedatais not a trusted-CAS login URL, does not reveal a service URL; fall back to a separately authorized safe probe, explicit--cas-service-url, or the browser fallback. - A
403can mean the account lacks a role or permission. Fetch once only if there was no valid Cookie; if a fresh Cookie still receives403, stop and report an authorization problem instead of looping. - Retry automatically only for idempotent reads (
GET,HEAD) after a fresh Cookie. Do not silently retry side-effecting calls such as publish, offline, create, update, or delete; confirm the operation is idempotent or ask before repeating it.
Fetch a Cookie
Run the bundled script from the installed Skill directory only after the user
has authorized the authentication attempt. It accepts a username via --username
or SITE_USERNAME; it reads SITE_PASSWORD when supplied and otherwise prompts
in an interactive terminal. It never accepts a password as a command-line
argument.
COOKIE_FILE="$(mktemp)"
python <skill-root>/scripts/fetch_cookie.py \
--url https://internal-ad.gaotu100.com/welcome \
--output "$COOKIE_FILE" \
--username your-accountFor an unknown host whose safe read-only URL has been authorized, let the helper
derive the service URL from a trusted CAS redirect or code/errorCode:700 JSON body:
python <skill-root>/scripts/fetch_cookie.py \
--url https://internal-service.example.com/api/status \
--discover-cas \
--output "$COOKIE_FILE" \
--username your-accountFor a write operation, do not use the write endpoint as an authentication probe.
Ask for or locate a safe read-only probe URL first. If discovery finds no trusted
CAS signal (neither a redirect nor a code/errorCode:700 data login URL), stop and
request an explicit --cas-service-url rather than guessing a login route.
For the narrow HTTP callback exception, provide the original service URL
explicitly; do not rewrite the CAS service to HTTPS and do not expect
--discover-cas to produce the ticket-bearing callback.
The output file has mode 0600 and contains only the Cookie header value. Pass
it to programs that support --cookie-file, then remove it as soon as the
operation is complete:
python /path/to/your-project/api_client.py --cookie-file "$COOKIE_FILE" --execute
rm -f "$COOKIE_FILE"For new Python scripts, prefer a local helper that follows the same precedence: explicit Cookie, Cookie file, documented environment variable, then this CAS fetch flow. Keep the Cookie in memory or a protected file; do not print it.
From a curl Command to an Authenticated Call
When the user pastes a browser "copy as cURL" command, do not hardcode its
Cookie. Recognize it as an authenticated internal request and wrap it. The output
form is up to the situation — a one-off command, a small bash function, a Python
client in the user's codebase, or the bundled scripts/call_api.py reference.
Whatever the form, follow these principles.
- Recognize the auth. The CAS session cookies (
SESSION,JSESSIONID,cas_name,CAS_AC_CURRENT_ROLE,uid) in the-b/Cookievalue mark the request as CAS-authenticated. Treat the pasted Cookie as evidence only; never reuse it — it will expire and must not be committed. - Handle the Cookie, not the paste. Obtain a fresh Cookie for the target host
with
scripts/fetch_cookie.py(use--discover-casfor a non-built-in host, or--cas-service-url). Keep it in memory or a0600file, set it as the wholeCookieheader, and never print or log it. In bash:curl -H "Cookie: $(cat "$COOKIE_FILE")" ...; in Python, read the file or importfetch_cookie. - Keep the wrapper minimal. Forward only what the endpoint needs — usually just
the Cookie plus
content-typewhen there is a JSON body. Drop everything else the browser attached:origin,referer,priority,sec-ch-*,sec-fetch-*,accept-language,user-agent, and identity headers likeuid(the Cookie already carries identity). Start minimal and add a header back only if the call fails without it. (Measured example:test-mineeds only the Cookie +content-type;b_client,accept,uidare all unnecessary.) - Gate side effects. Replay
GET/HEADfreely. APOSTthat is plainly a read (a/list,/query,/search, or/detailcall) is lower risk but still confirm if unsure. Do not auto-retry a side-effecting call.
🔴 CHECKPOINT — 🛑 STOP before replaying any
POST/PUT/PATCH/DELETE. Get explicit user confirmation that the request is safe to replay, because a pasted write may create, update, or delete. Never send or auto-retry a side-effecting call without it (call_api.pyenforces this via--confirm-write).
Reference implementation (optional): scripts/call_api.py embodies the above —
minimal allowlist headers (--keep-header to add more), a --confirm-write
gate that refuses to send a non-GET/HEAD method until the user confirms, and
one auth-refresh retry for reads only. It prints the response body to stdout and
the host/status/header decisions to stderr; the Cookie never appears in either.
# read (GET/HEAD or a clearly read-only POST like /list, after confirming):
python <skill-root>/scripts/call_api.py --curl-file request.curl \
--discover-cas --username your-account
# side-effecting method, only after the user confirms it is safe to replay:
python <skill-root>/scripts/call_api.py --curl-file request.curl \
--discover-cas --username your-account --confirm-writeCredential and Logging Rules
- Do not add a
--passwordoption. Prompt withgetpassor read a named environment variable. - Do not put usernames, passwords, Cookie values, or request headers containing Cookies in source control, terminal output, errors, tests, or chat messages.
- Pass a password only through the child process environment. Do not add it to a command list, command string, URL, or log.
- Mask authentication headers in debug logs. Report only host, status code, and a short non-sensitive error summary.
- Do not persist Cookies beyond the requested operation unless the user has explicitly asked for a protected local cache and its expiry behavior is known.
Failure Handling
- Login failure (bad account/password, CAS did not return the expected fields): surface the script's sanitized error; do not expose credentials. Do not invent a browser, SSO, or alternate password source.
- Unknown host with no trusted CAS redirect and no
code/errorCode:700datapointing at a trusted CAS login URL: stop and request an explicit--cas-service-urlor browser fallback. Do not guess from a bare401, an HTML login page, or an untrusted redirect/datavalue. - Fresh Cookie with
403: report that authentication succeeded but the account may lack authorization; do not repeatedly refresh the session.
Do Not (Anti-patterns)
- Do not reuse, hardcode, or commit a pasted or browser-exported Cookie — it expires and leaks the session.
- Do not guess a CAS service URL from a bare
401, an HTML login page, or an untrusted redirect /code/errorCode:700data; require--cas-service-urlor the browser fallback instead. - Do not replay a
POST/PUT/PATCH/DELETEwithout explicit user confirmation, and never auto-retry a side-effecting call. - Do not forward browser-noise headers by default; keep the wrapper minimal
(Cookie +
content-type), adding others back only when a call fails without them. - Do not add a
--passwordflag or place credentials or Cookies in argv, URLs, logs, errors, tests, or chat; pass a password only via the child-process env. - Do not loop-refresh the session on a
403; treat it as a likely authorization gap, not a stale Cookie.
Completion Report
State whether an existing Cookie was reused or a fresh Cookie was fetched, the target host, and whether the API call was attempted. Never include the Cookie or password in the report.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

