Skip to content

Commit c37902f

Browse files
committed
fix: normalize IPv4-mapped IPv6 addresses in subscription URLs
Strip ::ffff: prefix from client IPs when building subscription URLs and clean up existing subscriptions with bracketed IPv4-mapped IPv6 addresses during the periodic cleanup cycle.
1 parent 5e8731f commit c37902f

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

services/parse-notify-params.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ function parseUrlList(argv) {
2929
}
3030

3131
function glueUrlParts(scheme, client, port, path) {
32+
if (client.startsWith('::ffff:')) {
33+
client = client.slice(7);
34+
}
35+
3236
if (client.indexOf(':') > -1) {
3337
client = `[${client}]`;
3438
}

services/remove-expired-subscriptions.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,36 @@ async function removeExpiredSubscriptions() {
7272
}
7373
}
7474

75+
// Fix IPv4-mapped IPv6 addresses in subscription URLs (e.g. [::ffff:1.2.3.4] -> 1.2.3.4)
76+
let urlsFixed = 0;
77+
const fixCursor = collection.find({ 'pleaseNotify.url': { $regex: '::ffff:' } });
78+
79+
while (await fixCursor.hasNext()) {
80+
const doc = await fixCursor.next();
81+
let changed = false;
82+
83+
for (const subscription of doc.pleaseNotify) {
84+
const fixed = subscription.url.replace(/\[::ffff:([^\]]+)\]/, '$1');
85+
if (fixed !== subscription.url) {
86+
subscription.url = fixed;
87+
changed = true;
88+
urlsFixed++;
89+
}
90+
}
91+
92+
if (changed) {
93+
await collection.updateOne(
94+
{ _id: doc._id },
95+
{ $set: { pleaseNotify: doc.pleaseNotify } }
96+
);
97+
jsonStore.setSubscriptions(doc._id, doc.pleaseNotify);
98+
}
99+
}
100+
101+
if (urlsFixed > 0) {
102+
console.log(`Fixed ${urlsFixed} subscription URLs with IPv4-mapped IPv6 addresses`);
103+
}
104+
75105
// Find subscriptions with no corresponding resource and create resources
76106
let resourcesCreated = 0;
77107
const orphanedCursor = collection.aggregate([
@@ -104,13 +134,14 @@ async function removeExpiredSubscriptions() {
104134
console.log(`Created ${resourcesCreated} missing resource documents`);
105135
}
106136

107-
console.log(`Subscription cleanup completed: ${totalRemoved} expired/errored subscriptions removed, ${documentsProcessed} documents processed, ${documentsDeleted} empty documents deleted`);
137+
console.log(`Subscription cleanup completed: ${totalRemoved} expired/errored subscriptions removed, ${documentsProcessed} documents processed, ${documentsDeleted} empty documents deleted, ${urlsFixed} URLs fixed`);
108138

109139
return {
110140
subscriptionsRemoved: totalRemoved,
111141
documentsProcessed,
112142
documentsDeleted,
113-
resourcesCreated
143+
resourcesCreated,
144+
urlsFixed
114145
};
115146

116147
} catch (error) {

0 commit comments

Comments
 (0)