Skip to content

fix(online): allow configuring the raw repository base - #30

Merged
pentaoa merged 1 commit into
wormforce:mainfrom
FortuneCatOfSummer:fix/online-configurable-raw-base
Oct 26, 2026
Merged

pentaoa merged 1 commit into
wormforce:mainfrom
FortuneCatOfSummer:fix/online-configurable-raw-base

Conversation

@FortuneCatOfSummer

Copy link
Copy Markdown
Contributor

Summary

  • Resolve the SUSTech Online raw base from SUSTECH_ONLINE_RAW_BASE, defaulting
    to https://raw.githubusercontent.com/SUSTech-CRA/sustech-online-ng/master
  • Derive the raw allowlist origin and path prefix from the same base, so exact
    URL matching and redirect rejection remain unchanged
  • Reject non-HTTPS values, and values with a query string or fragment, with
    ONLINE_RAW_BASE_INVALID
  • Update service endpoint metadata and document the variable in docs/ONLINE.md

Closes #29

Why

On networks that cannot reach raw.githubusercontent.com, every online
command fails with NETWORK_ERROR while sustech.online stays reachable.
0.13.0 offers no way to point the raw reads at a mirror.

Behaviour

  • No environment variable: identical to today.
  • SUSTECH_ONLINE_RAW_BASE=https://ghfast.top/https://raw.githubusercontent.com/SUSTech-CRA/sustech-online-ng/master:
    raw reads go through the mirror; the allowlist accepts exactly the
    constructed URL.
  • Invalid value: the command fails with ONLINE_RAW_BASE_INVALID instead of
    silently reading another source.

Tests

  • npm run check
  • npm test — new src/test/online-raw-base.test.ts covers the default, a
    mirror override, trailing-slash/whitespace trimming, invalid values, and
    import-time resolution.
  • Five pre-existing symlink tests fail on Windows without Developer Mode
    (EPERM: symlink); the other 484 tests pass, including 38 online-related
    tests.

Security

Redirects are still rejected (redirect: "error") and the final URL must match
the constructed target exactly. The allowlist is derived from the configured
base rather than a second hard-coded host.

The online commands hard-code raw.githubusercontent.com for the public
SUSTech Online Markdown. On networks where that host is unreachable, every
online command fails with NETWORK_ERROR even though the rendered site is
available.

Resolve the raw base from SUSTECH_ONLINE_RAW_BASE (HTTPS, no query or
fragment), defaulting to the current public repository URL. The allowlist
origin and path are derived from the same base, so exact URL matching and
redirect rejection remain enforced.

Add tests for the default, a mirror override, invalid values, and
import-time resolution, and document the variable in docs/ONLINE.md.
Copilot AI balanced review requested due to automatic review settings October 23, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@pentaoa
pentaoa merged commit b86f3b8 into wormforce:main Oct 26, 2026

pentaoa commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks @FortuneCatOfSummer — this is a clean fix for a real pain point on networks that cannot reach raw.githubusercontent.com, and keeping the default + allowlist/redirect behaviour intact is appreciated. Merged.

Follow-up: as you noted in #29, src/calendar/client.ts still hard-codes the same raw GitHub base (sustech calendar day / related paths). A matching configurable base (or sharing the same env mechanism) would be a natural next PR if you are interested.

pentaoa pushed a commit that referenced this pull request Oct 30, 2026
* fix(calendar): allow configuring the raw repository base

The calendar client still hard-codes raw.githubusercontent.com, so
`calendar day` and `tis schedule` fail on networks where that host is
unreachable even after the online layer became configurable.

Extract the HTTPS base resolution shared with the online layer and add
SUSTECH_CALENDAR_RAW_BASE, defaulting to the public calendar repository.
Values must be plain HTTPS URLs without a query or fragment; invalid
values fail with CALENDAR_RAW_BASE_INVALID.

Also make the online default-base test hermetic when
SUSTECH_ONLINE_RAW_BASE is set in the caller's environment, and document
both variables in the README.

Refs #29, #30.

* fix(core): reject credentials in configured raw bases

A base URL such as https://user:token@mirror.example/repo would send the
embedded secret to the mirror. Reject any URL with userinfo so
SUSTECH_CALENDAR_RAW_BASE and SUSTECH_ONLINE_RAW_BASE cannot smuggle
credentials into requests.

Cover both resolvers with tests and update the README and online docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] SUSTech Online commands fail on networks that cannot reach raw.githubusercontent.com

3 participants