Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mastodon compatibility #1238

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ const InboxService = {
}

if (!ctx.meta.skipSignatureValidation) {
if (!ctx.meta.rawBody || !ctx.meta.headers)
throw new Error(`Cannot validate HTTP signature because of missing meta (rawBody or headers)`);
if (!ctx.meta.rawBody || !ctx.meta.originalHeaders)
throw new Error(`Cannot validate HTTP signature because of missing meta (rawBody or originalHeaders)`);

const validDigest = await ctx.call('signature.verifyDigest', {
body: ctx.meta.rawBody, // Stored by parseJson middleware
headers: ctx.meta.headers
headers: ctx.meta.originalHeaders
});

const { isValid: validSignature } = await ctx.call('signature.verifyHttpSignature', {
url: collectionUri,
method: 'POST',
headers: ctx.meta.headers
headers: ctx.meta.originalHeaders
});

if (!validDigest || !validSignature) {
Expand Down
9 changes: 7 additions & 2 deletions src/middleware/packages/ldp/services/api/actions/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ module.exports = async function get(ctx) {
jsonContext: parseJson(ctx.meta.headers?.jsonldcontext)
})
);

ctx.meta.$responseType = ctx.meta.$responseType || accept;
if (ctx.meta.$responseType === 'application/ld+json')
ctx.meta.$responseType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`;
} else if (types.includes('https://www.w3.org/ns/activitystreams#Collection')) {
/*
* AS COLLECTION
Expand All @@ -45,7 +48,7 @@ module.exports = async function get(ctx) {
jsonContext: parseJson(ctx.meta.headers?.jsonldcontext)
})
);
ctx.meta.$responseType = 'application/ld+json';
ctx.meta.$responseType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`;
} else {
/*
* LDP RESOURCE
Expand All @@ -55,7 +58,7 @@ module.exports = async function get(ctx) {
...ctx.meta.headers
};

if (ctx.meta.accepts && ctx.meta.accepts.includes('text/html') && this.settings.preferredViewForResource) {
if (ctx.meta.originalHeaders?.accept?.includes('text/html') && this.settings.preferredViewForResource) {
const webId = ctx.meta.webId || 'anon';
const resourceExist = await ctx.call('ldp.resource.exist', { resourceUri: uri, webId });
if (resourceExist) {
Expand Down Expand Up @@ -95,6 +98,8 @@ module.exports = async function get(ctx) {
}
} else {
ctx.meta.$responseType = ctx.meta.$responseType || accept;
if (ctx.meta.$responseType === 'application/ld+json')
ctx.meta.$responseType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/middleware/packages/middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const Busboy = require('busboy');
const streams = require('memory-streams');

const parseHeader = async (req, res, next) => {
req.$ctx.meta.headers = req.headers || {};
req.$ctx.meta.headers = req.headers ? { ...req.headers } : {};
// Also remember original headers (needed for HTTP signatures verification and files type negociation)
req.$ctx.meta.originalHeaders = req.headers ? { ...req.headers } : {};
next();
};

Expand Down Expand Up @@ -37,8 +39,6 @@ const throw500 = msg => {

const negotiateAccept = (req, res, next) => {
if (!req.$ctx.meta.headers) req.$ctx.meta.headers = {};
// we keep the full list for further use
req.$ctx.meta.accepts = req.headers.accept;
if (req.headers.accept === '*/*') {
delete req.headers.accept;
}
Expand Down