Skip to content

Commit edce0ca

Browse files
committed
feat: add --external-links flag for cross-origin links
Adds opt-in support for external (cross-origin) links in HTML directory listings, resolving issue #135. When --external-links is passed, the HTML parser detects <a href> tags pointing to different origins, extracts the filename, and exposes those files and directories alongside the local listing. Key design & security decisions: - First-wins deduplication: if two external links produce the same filename, the first one encountered is kept. - HTTP credentials (-u/-p) are scoped to the mounted (root) server only. External servers returning HTTP 401/403 trigger a user-visible warning. - External links ending with '/' are treated as directories; navigating into them triggers a recursive LinkTable_new() on the remote URL. - LinkTable_fill() detects pre-populated f_url and skips URL construction for external links. - Same-origin URLs shorter than ROOT_LINK_OFFSET are protected from buffer over-reads. - Made URL scheme and host comparisons case-insensitive per RFC 3986 in is_external_url and is_cross_origin. - Stripped fragment identifiers (#) along with query parameters when extracting filenames in external_url_to_filename. - Sanitized unescaped path in LinkTable_new to prevent path traversal via ".." for external links. - Ignored "." and ".." filenames when parsing external links. - Refactored LinkHashSet_free to avoid const-cast qualifier drop. - Sanitized URL-decoded slash characters in external filenames to prevent path traversal or invalid FUSE entry names.
1 parent ab5f6f0 commit edce0ca

7 files changed

Lines changed: 1034 additions & 54 deletions

File tree

USAGE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ HTTPDirFS supports the following usage flags:
4949
--zero-len-is-dir If a file has a zero length, treat it as a directory
5050
--insecure-tls Disable licurl TLS certificate verification by
5151
setting CURLOPT_SSL_VERIFYHOST to 0
52+
--external-links Include external (cross-origin) links from
53+
directory listings. When enabled, httpdirfs will
54+
follow <a href> tags pointing to other servers
55+
and expose their files alongside local links.
56+
HTTP credentials (-u/-p) are only applied to
57+
the mounted server; external servers requiring
58+
authentication will generate a warning.
5259
--single-file-mode Single file mode - rather than mounting a whole
5360
directory, present a single file inside a virtual
5461
directory.

src/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ typedef struct {
115115
int refresh_timeout;
116116
/** \brief Try refreshing invalid links when reading a directory */
117117
int invalid_refresh;
118+
/** \brief Include external (cross-origin) links from directory listings */
119+
int external_links;
118120
/*--------------- Cache related ---------------*/
119121
/** \brief Whether cache mode is enabled */
120122
int cache_enabled;

0 commit comments

Comments
 (0)