Skip to content

Update api.js and bot.js: supporting custom referer header#694

Merged
macbre merged 4 commits intomacbre:develfrom
TimXiedada:devel
Oct 30, 2025
Merged

Update api.js and bot.js: supporting custom referer header#694
macbre merged 4 commits intomacbre:develfrom
TimXiedada:devel

Conversation

@TimXiedada
Copy link
Copy Markdown
Contributor

@TimXiedada TimXiedada commented Oct 30, 2025

A new parameter added to allow users specify a custom referer. This option is inspired by WikiFur, a wiki site that applied referer checking on API endpoints (it seems ridiculous):

# Node.js network inspection for failed request, in curl format
curl -v -H 'user-agent: nodemw/0.24.1 (node.js v22.17.0; win32 x64)' -H 'host: zh.wikifur.com' -H 'cookie: zh_session=[redacted for privacy]' 'http://zh.wikifur.com/w/api.php?action=query&prop=info&intoken=edit&titles=[redacted for privacy]&format=json'
< HTTP 403
< date: Thu, 30 Oct 2025 02:59:26 GMT
< server: Apache/2.4.65 (FreeBSD)
< content-length: 199
< connection: close
< content-type: text/html; charset=iso-8859-1
<

Referer checking is obviously performed by Apache.

Adding referer header to api call within my fork solves this problem. It was originally a small hack, but I finally made it standarized, wrote a test case for it and it passed.

@TimXiedada
Copy link
Copy Markdown
Contributor Author

I don't know whether the behavior of preparing referer header is appropriate, so I left this PR as a draft until we determine this behavior.

@macbre macbre self-assigned this Oct 30, 2025
@macbre
Copy link
Copy Markdown
Owner

macbre commented Oct 30, 2025

Thanks for the PR!

Please run npx prettier --write . to fix the CI checks.

@TimXiedada TimXiedada marked this pull request as ready for review October 30, 2025 06:40
Copy link
Copy Markdown
Owner

@macbre macbre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @TimXiedada!

@macbre macbre merged commit e85ff76 into macbre:devel Oct 30, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants