Skip to content

Commit cc7a71c

Browse files
committed
fix(nextcloud): Send cookies when acquiring CSRF token
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent e37b775 commit cc7a71c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/nextcloud/lib/src/webdav/csrf_client.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:dynamite_runtime/http_client.dart';
2+
import 'package:dynamite_runtime/utils.dart';
23
import 'package:http/http.dart' as http;
34

45
/// A [http.Client] that sends the Nextcloud CSRF token.
@@ -20,14 +21,17 @@ final class WebDavCSRFClient with http.BaseClient {
2021
@override
2122
Future<http.StreamedResponse> send(http.BaseRequest request) async {
2223
if (_token == null) {
23-
final response = await _inner.get(Uri.parse('${_inner.baseURL}/index.php'));
24+
final response = await _inner.send(http.Request('GET', Uri.parse('${_inner.baseURL}/index.php')));
2425
if (response.statusCode >= 300) {
2526
throw DynamiteStatusCodeException(
2627
response.statusCode,
2728
);
2829
}
2930

30-
_token = RegExp('data-requesttoken="([^"]*)"').firstMatch(response.body)!.group(1);
31+
final encoding = encodingForHeaders(response.headers);
32+
final body = await response.stream.bytesToString(encoding);
33+
34+
_token = RegExp('data-requesttoken="([^"]*)"').firstMatch(body)!.group(1);
3135
}
3236

3337
request.headers.addAll({

0 commit comments

Comments
 (0)