Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15378350
D14105.id34089.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D14105.id34089.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1621,6 +1621,7 @@
'PhabricatorAuthManagementRefreshWorkflow' => 'applications/auth/management/PhabricatorAuthManagementRefreshWorkflow.php',
'PhabricatorAuthManagementStripWorkflow' => 'applications/auth/management/PhabricatorAuthManagementStripWorkflow.php',
'PhabricatorAuthManagementTrustOAuthClientWorkflow' => 'applications/auth/management/PhabricatorAuthManagementTrustOAuthClientWorkflow.php',
+ 'PhabricatorAuthManagementUnlimitWorkflow' => 'applications/auth/management/PhabricatorAuthManagementUnlimitWorkflow.php',
'PhabricatorAuthManagementUntrustOAuthClientWorkflow' => 'applications/auth/management/PhabricatorAuthManagementUntrustOAuthClientWorkflow.php',
'PhabricatorAuthManagementVerifyWorkflow' => 'applications/auth/management/PhabricatorAuthManagementVerifyWorkflow.php',
'PhabricatorAuthManagementWorkflow' => 'applications/auth/management/PhabricatorAuthManagementWorkflow.php',
@@ -5472,6 +5473,7 @@
'PhabricatorAuthManagementRefreshWorkflow' => 'PhabricatorAuthManagementWorkflow',
'PhabricatorAuthManagementStripWorkflow' => 'PhabricatorAuthManagementWorkflow',
'PhabricatorAuthManagementTrustOAuthClientWorkflow' => 'PhabricatorAuthManagementWorkflow',
+ 'PhabricatorAuthManagementUnlimitWorkflow' => 'PhabricatorAuthManagementWorkflow',
'PhabricatorAuthManagementUntrustOAuthClientWorkflow' => 'PhabricatorAuthManagementWorkflow',
'PhabricatorAuthManagementVerifyWorkflow' => 'PhabricatorAuthManagementWorkflow',
'PhabricatorAuthManagementWorkflow' => 'PhabricatorManagementWorkflow',
diff --git a/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php b/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php
--- a/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php
+++ b/src/applications/auth/factor/PhabricatorTOTPAuthFactor.php
@@ -192,9 +192,6 @@
PhutilOpaqueEnvelope $key,
$code) {
- // TODO: This should use rate limiting to prevent multiple attempts in a
- // short period of time.
-
$now = (int)(time() / 30);
// Allow the user to enter a code a few minutes away on either side, in
diff --git a/src/applications/auth/management/PhabricatorAuthManagementUnlimitWorkflow.php b/src/applications/auth/management/PhabricatorAuthManagementUnlimitWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/auth/management/PhabricatorAuthManagementUnlimitWorkflow.php
@@ -0,0 +1,67 @@
+<?php
+
+final class PhabricatorAuthManagementUnlimitWorkflow
+ extends PhabricatorAuthManagementWorkflow {
+
+ protected function didConstruct() {
+ $this
+ ->setName('unlimit')
+ ->setExamples('**unlimit** --user __username__ --all')
+ ->setSynopsis(
+ pht(
+ 'Reset action counters so a user can continue taking '.
+ 'rate-limited actions.'))
+ ->setArguments(
+ array(
+ array(
+ 'name' => 'user',
+ 'param' => 'username',
+ 'help' => pht('Reset action counters for this user.'),
+ ),
+ array(
+ 'name' => 'all',
+ 'help' => pht('Reset all counters.'),
+ ),
+ ));
+ }
+
+ public function execute(PhutilArgumentParser $args) {
+ $username = $args->getArg('user');
+ if (!strlen($username)) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Use --user to choose a user to reset actions for.'));
+ }
+
+ $user = id(new PhabricatorPeopleQuery())
+ ->setViewer($this->getViewer())
+ ->withUsernames(array($username))
+ ->executeOne();
+ if (!$user) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'No user exists with username "%s".',
+ $username));
+ }
+
+ $all = $args->getArg('all');
+ if (!$all) {
+ // TODO: Eventually, let users reset specific actions. For now, we
+ // require `--all` so that usage won't change when you can reset in a
+ // more tailored way.
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Specify --all to reset all action counters.'));
+ }
+
+ $count = PhabricatorSystemActionEngine::resetActions(
+ array(
+ $user->getPHID(),
+ ));
+
+ echo pht('Reset %s action(s).', new PhutilNumber($count))."\n";
+
+ return 0;
+ }
+
+}
diff --git a/src/applications/system/engine/PhabricatorSystemActionEngine.php b/src/applications/system/engine/PhabricatorSystemActionEngine.php
--- a/src/applications/system/engine/PhabricatorSystemActionEngine.php
+++ b/src/applications/system/engine/PhabricatorSystemActionEngine.php
@@ -167,4 +167,35 @@
return phutil_units('1 hour in seconds');
}
+
+ /**
+ * Reset all action counts for actions taken by some set of actors in the
+ * previous action window.
+ *
+ * @param list<string> Actors to reset counts for.
+ * @return int Number of actions cleared.
+ */
+ public static function resetActions(array $actors) {
+ $log = new PhabricatorSystemActionLog();
+ $conn_w = $log->establishConnection('w');
+
+ $now = PhabricatorTime::getNow();
+
+ $hashes = array();
+ foreach ($actors as $actor) {
+ $hashes[] = PhabricatorHash::digestForIndex($actor);
+ }
+
+ queryfx(
+ $conn_w,
+ 'DELETE FROM %T
+ WHERE actorHash IN (%Ls) AND epoch BETWEEN %d AND %d',
+ $log->getTableName(),
+ $hashes,
+ $now - self::getWindow(),
+ $now);
+
+ return $conn_w->getAffectedRows();
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mar 14 2025, 1:54 PM (5 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7658794
Default Alt Text
D14105.id34089.diff (5 KB)
Attached To
Mode
D14105: Add `bin/auth unlimit` and clean up a TODO
Attached
Detach File
Event Timeline
Log In to Comment