Skip to content

Commit a1ed198

Browse files
authored
Merge pull request #47445 from nextcloud/backport/44369/stable28
[stable28] fix: csrf check failed on public share with password
2 parents 904345b + 64c702b commit a1ed198

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

core/src/main.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import './jquery/index.js'
3636
import { initCore } from './init.js'
3737
import { registerAppsSlideToggle } from './OC/apps.js'
3838
import { getRequestToken } from '@nextcloud/auth'
39+
import { generateUrl } from '@nextcloud/router'
40+
import Axios from '@nextcloud/axios'
3941

4042
// eslint-disable-next-line camelcase
4143
__webpack_nonce__ = btoa(getRequestToken())
@@ -51,3 +53,20 @@ window.addEventListener('DOMContentLoaded', function() {
5153
window.onhashchange = _.bind(OC.Util.History._onPopState, OC.Util.History)
5254
}
5355
})
56+
57+
// Fix error "CSRF check failed"
58+
document.addEventListener('DOMContentLoaded', function() {
59+
const form = document.getElementById('password-input-form')
60+
if (form) {
61+
form.addEventListener('submit', async function(event) {
62+
event.preventDefault()
63+
const requestToken = document.getElementById('requesttoken')
64+
if (requestToken) {
65+
const url = generateUrl('/csrftoken')
66+
const resp = await Axios.get(url)
67+
requestToken.value = resp.data.token
68+
}
69+
form.submit()
70+
})
71+
}
72+
})

core/templates/publicshareauth.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<?php endif; ?>
2323
<p>
2424
<label for="password" class="infield"><?php p($l->t('Password')); ?></label>
25-
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
25+
<input type="hidden" id="requesttoken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
2626
<input type="password" name="password" id="password"
2727
placeholder="<?php p($l->t('Password')); ?>" value=""
2828
autocomplete="new-password" autocapitalize="off" spellcheck="false"
@@ -34,7 +34,7 @@ class="svg icon-confirm input-button-inline" value="" disabled="disabled" />
3434
</p>
3535
</fieldset>
3636
</form>
37-
37+
3838
<!-- email prompt form. It should initially be hidden -->
3939
<?php if (isset($_['identityOk'])): ?>
4040
<form method="post" id="email-input-form">
@@ -46,7 +46,7 @@ class="svg icon-confirm input-button-inline" value="" disabled="disabled" />
4646
<p>
4747
<input type="email" id="email" name="identityToken" placeholder="<?php p($l->t('Email address')); ?>" />
4848
<input type="submit" id="password-request" name="passwordRequest" class="svg icon-confirm input-button-inline" value="" disabled="disabled"/>
49-
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
49+
<input type="hidden" id="requesttoken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
5050
<input type="hidden" name="sharingToken" value="<?php p($_['share']->getToken()) ?>" id="sharingToken">
5151
<input type="hidden" name="sharingType" value="<?php p($_['share']->getShareType()) ?>" id="sharingType">
5252
</p>
@@ -59,12 +59,12 @@ class="svg icon-confirm input-button-inline" value="" disabled="disabled" />
5959
<?php endif; ?>
6060
</fieldset>
6161
</form>
62-
62+
6363
<!-- request password button -->
6464
<?php if (!isset($_['identityOk']) && $_['share']->getShareType() === $_['share']::TYPE_EMAIL && !$_['share']->getSendPasswordByTalk()): ?>
6565
<a id="request-password-button-not-talk"><?php p($l->t('Forgot password?')); ?></a>
6666
<?php endif; ?>
67-
67+
6868
<!-- back to showShare button -->
6969
<form method="get">
7070
<fieldset>

dist/core-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)