Skip to content

Commit

Permalink
fix: Undo authorization on OPTIONS requests
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Apr 4, 2022
1 parent 48efc6f commit 97e600b
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 101 deletions.
2 changes: 1 addition & 1 deletion config/http/middleware/handlers/cors.json
Expand Up @@ -15,7 +15,7 @@
"DELETE"
],
"options_credentials": true,
"options_preflightContinue": true,
"options_preflightContinue": false,
"options_exposedHeaders": [
"Accept-Patch",
"Accept-Post",
Expand Down
4 changes: 0 additions & 4 deletions config/ldp/handler/components/operation-handler.json
Expand Up @@ -5,10 +5,6 @@
"@id": "urn:solid-server:default:OperationHandler",
"@type": "WaterfallHandler",
"handlers": [
{
"@type": "OptionsOperationHandler",
"resourceSet": { "@id": "urn:solid-server:default:CachedResourceSet" }
},
{
"@type": "GetOperationHandler",
"store": { "@id": "urn:solid-server:default:ResourceStore" }
Expand Down
36 changes: 0 additions & 36 deletions src/http/ldp/OptionsOperationHandler.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/http/output/response/NoContentResponseDescription.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/index.ts
Expand Up @@ -83,7 +83,6 @@ export * from './http/ldp/DeleteOperationHandler';
export * from './http/ldp/GetOperationHandler';
export * from './http/ldp/HeadOperationHandler';
export * from './http/ldp/OperationHandler';
export * from './http/ldp/OptionsOperationHandler';
export * from './http/ldp/PatchOperationHandler';
export * from './http/ldp/PostOperationHandler';
export * from './http/ldp/PutOperationHandler';
Expand All @@ -106,7 +105,6 @@ export * from './http/output/metadata/WwwAuthMetadataWriter';

// HTTP/Output/Response
export * from './http/output/response/CreatedResponseDescription';
export * from './http/output/response/NoContentResponseDescription';
export * from './http/output/response/OkResponseDescription';
export * from './http/output/response/ResetResponseDescription';
export * from './http/output/response/ResponseDescription';
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Middleware.test.ts
Expand Up @@ -70,7 +70,7 @@ describe('An http server with middleware', (): void => {
.set('Access-Control-Request-Headers', 'content-type')
.set('Access-Control-Request-Method', 'POST')
.set('Host', 'test.com')
.expect(200);
.expect(204);
expect(res.header).toEqual(expect.objectContaining({
'access-control-allow-origin': '*',
'access-control-allow-headers': 'content-type',
Expand Down
10 changes: 7 additions & 3 deletions test/integration/PermissionTable.test.ts
Expand Up @@ -44,9 +44,13 @@ const allModes = [ AM.read, AM.append, AM.create, AM.write, AM.delete ];
// For PUT/PATCH/DELETE we return 205 instead of 200/204
/* eslint-disable no-multi-spaces */
const table: [string, string, AM[], AM[] | undefined, string, string, number, number][] = [
[ 'OPTIONS', 'C/R', [], undefined, '', '', 401, 401 ],
[ 'OPTIONS', 'C/R', [], [ AM.read ], '', '', 204, 404 ],
[ 'OPTIONS', 'C/R', [ AM.read ], undefined, '', '', 204, 404 ],
// No authorization headers are sent in an OPTIONS request making it impossible to grant permission.
// See https://github.com/CommunitySolidServer/CommunitySolidServer/issues/1246#issuecomment-1087325235
// From https://fetch.spec.whatwg.org/#cors-preflight-fetch it follows
// that a preflight check should always return an OK response.
[ 'OPTIONS', 'C/R', [], undefined, '', '', 204, 204 ],
[ 'OPTIONS', 'C/R', [], [ AM.read ], '', '', 204, 204 ],
[ 'OPTIONS', 'C/R', [ AM.read ], undefined, '', '', 204, 204 ],

[ 'HEAD', 'C/R', [], undefined, '', '', 401, 401 ],
[ 'HEAD', 'C/R', [], [ AM.read ], '', '', 200, 404 ],
Expand Down
44 changes: 0 additions & 44 deletions test/unit/http/ldp/OptionsOperationHandler.test.ts

This file was deleted.

0 comments on commit 97e600b

Please sign in to comment.