##// END OF EJS Templates
wireproto: check permissions when executing "batch" command (BC) (SEC)...
Gregory Szorc -
r36773:ff4bc0ab stable
parent child Browse files
Show More
@@ -360,8 +360,10 b' class hgweb(object):'
360 try:
360 try:
361 if query:
361 if query:
362 raise ErrorResponse(HTTP_NOT_FOUND)
362 raise ErrorResponse(HTTP_NOT_FOUND)
363
364 req.checkperm = lambda op: self.check_perm(rctx, req, op)
363 if cmd in perms:
365 if cmd in perms:
364 self.check_perm(rctx, req, perms[cmd])
366 req.checkperm(perms[cmd])
365 return protocol.call(rctx.repo, req, cmd)
367 return protocol.call(rctx.repo, req, cmd)
366 except ErrorResponse as inst:
368 except ErrorResponse as inst:
367 # A client that sends unbundle without 100-continue will
369 # A client that sends unbundle without 100-continue will
@@ -52,6 +52,7 b' class webproto(wireproto.abstractserverp'
52 self.response = ''
52 self.response = ''
53 self.ui = ui
53 self.ui = ui
54 self.name = 'http'
54 self.name = 'http'
55 self.checkperm = req.checkperm
55
56
56 def getargs(self, args):
57 def getargs(self, args):
57 knownargs = self._args()
58 knownargs = self._args()
@@ -689,6 +689,8 b" def wireprotocommand(name, args=''):"
689 return func
689 return func
690 return register
690 return register
691
691
692 # TODO define a more appropriate permissions type to use for this.
693 permissions['batch'] = 'pull'
692 @wireprotocommand('batch', 'cmds *')
694 @wireprotocommand('batch', 'cmds *')
693 def batch(repo, proto, cmds, others):
695 def batch(repo, proto, cmds, others):
694 repo = repo.filtered("served")
696 repo = repo.filtered("served")
@@ -701,6 +703,17 b' def batch(repo, proto, cmds, others):'
701 n, v = a.split('=')
703 n, v = a.split('=')
702 vals[unescapearg(n)] = unescapearg(v)
704 vals[unescapearg(n)] = unescapearg(v)
703 func, spec = commands[op]
705 func, spec = commands[op]
706
707 # If the protocol supports permissions checking, perform that
708 # checking on each batched command.
709 # TODO formalize permission checking as part of protocol interface.
710 if util.safehasattr(proto, 'checkperm'):
711 # Assume commands with no defined permissions are writes / for
712 # pushes. This is the safest from a security perspective because
713 # it doesn't allow commands with undefined semantics from
714 # bypassing permissions checks.
715 proto.checkperm(permissions.get(op, 'push'))
716
704 if spec:
717 if spec:
705 keys = spec.split()
718 keys = spec.split()
706 data = {}
719 data = {}
@@ -83,13 +83,12 b' web.deny_read=* prevents access to wire '
83 read not authorized
83 read not authorized
84 [1]
84 [1]
85
85
86 TODO batch command doesn't check permissions
87
88 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
86 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
89 200 Script output follows
87 401 read not authorized
90
88
91 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
89 0
92 publishing True (no-eol)
90 read not authorized
91 [1]
93
92
94 TODO custom commands don't check permissions
93 TODO custom commands don't check permissions
95
94
@@ -143,13 +142,12 b' web.deny_read=* with REMOTE_USER set sti'
143 read not authorized
142 read not authorized
144 [1]
143 [1]
145
144
146 TODO batch command doesn't check permissions
147
148 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
145 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
149 200 Script output follows
146 401 read not authorized
150
147
151 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
148 0
152 publishing True (no-eol)
149 read not authorized
150 [1]
153
151
154 TODO custom commands don't check permissions
152 TODO custom commands don't check permissions
155
153
@@ -201,13 +199,12 b' web.deny_read=<user> denies access to un'
201 read not authorized
199 read not authorized
202 [1]
200 [1]
203
201
204 TODO batch command doesn't check permissions
205
206 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
202 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
207 200 Script output follows
203 401 read not authorized
208
204
209 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
205 0
210 publishing True (no-eol)
206 read not authorized
207 [1]
211
208
212 TODO custom commands don't check permissions
209 TODO custom commands don't check permissions
213
210
@@ -254,13 +251,12 b' web.deny_read=<user> denies access to us'
254 read not authorized
251 read not authorized
255 [1]
252 [1]
256
253
257 TODO batch command doesn't check permissions
258
259 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
254 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
260 200 Script output follows
255 401 read not authorized
261
256
262 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
257 0
263 publishing True (no-eol)
258 read not authorized
259 [1]
264
260
265 TODO custom commands don't check permissions
261 TODO custom commands don't check permissions
266
262
@@ -461,13 +457,12 b' web.allow_read=<user> does not allow una'
461 read not authorized
457 read not authorized
462 [1]
458 [1]
463
459
464 TODO batch command doesn't check permissions
465
466 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
460 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
467 200 Script output follows
461 401 read not authorized
468
462
469 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
463 0
470 publishing True (no-eol)
464 read not authorized
465 [1]
471
466
472 TODO custom commands don't check permissions
467 TODO custom commands don't check permissions
473
468
@@ -514,13 +509,12 b' web.allow_read=<user> does not allow use'
514 read not authorized
509 read not authorized
515 [1]
510 [1]
516
511
517 TODO batch command doesn't check permissions
518
519 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
512 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
520 200 Script output follows
513 401 read not authorized
521
514
522 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
515 0
523 publishing True (no-eol)
516 read not authorized
517 [1]
524
518
525 TODO custom commands don't check permissions
519 TODO custom commands don't check permissions
526
520
@@ -621,13 +615,12 b' web.deny_read takes precedence over web.'
621 read not authorized
615 read not authorized
622 [1]
616 [1]
623
617
624 TODO batch command doesn't check permissions
625
626 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
618 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
627 200 Script output follows
619 401 read not authorized
628
620
629 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
621 0
630 publishing True (no-eol)
622 read not authorized
623 [1]
631
624
632 TODO custom commands don't check permissions
625 TODO custom commands don't check permissions
633
626
@@ -686,13 +679,12 b' web.allow-pull=false denies read access '
686 pull not authorized
679 pull not authorized
687 [1]
680 [1]
688
681
689 TODO batch command doesn't check permissions
690
691 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
682 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=listkeys+namespace%3Dphases'
692 200 Script output follows
683 401 pull not authorized
693
684
694 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 1
685 0
695 publishing True (no-eol)
686 pull not authorized
687 [1]
696
688
697 TODO custom commands don't check permissions
689 TODO custom commands don't check permissions
698
690
@@ -742,16 +734,18 b' Attempting a write command with HTTP GET'
742 push requires POST request
734 push requires POST request
743 [1]
735 [1]
744
736
745 TODO batch command doesn't check permissions
746
747 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
737 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
748 200 Script output follows
738 405 push requires POST request
749
739
750 1
740 0
741 push requires POST request
742 [1]
751
743
752 $ hg bookmarks
744 $ hg bookmarks
753 bm 0:cb9a9f314b8b
745 no bookmarks set
754 $ hg bookmark -d bm
746 $ hg bookmark -d bm
747 abort: bookmark 'bm' does not exist
748 [255]
755
749
756 TODO custom commands don't check permissions
750 TODO custom commands don't check permissions
757
751
@@ -781,16 +775,18 b' Attempting a write command with an unkno'
781 push requires POST request
775 push requires POST request
782 [1]
776 [1]
783
777
784 TODO batch command doesn't check permissions
785
786 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
778 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
787 200 Script output follows
779 405 push requires POST request
788
780
789 1
781 0
782 push requires POST request
783 [1]
790
784
791 $ hg bookmarks
785 $ hg bookmarks
792 bm 0:cb9a9f314b8b
786 no bookmarks set
793 $ hg bookmark -d bm
787 $ hg bookmark -d bm
788 abort: bookmark 'bm' does not exist
789 [255]
794
790
795 TODO custom commands don't check permissions
791 TODO custom commands don't check permissions
796
792
@@ -823,16 +819,15 b' Pushing on a plaintext channel is disabl'
823 ssl required
819 ssl required
824 [1]
820 [1]
825
821
826 TODO batch command doesn't check permissions
827
828 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
822 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
829 200 Script output follows
823 403 ssl required
830
824
831 1
825 0
826 ssl required
827 [1]
832
828
833 $ hg bookmarks
829 $ hg bookmarks
834 bm 0:cb9a9f314b8b
830 no bookmarks set
835 $ hg book -d bm
836
831
837 TODO custom commands don't check permissions
832 TODO custom commands don't check permissions
838
833
@@ -887,16 +882,15 b' web.deny_push=* denies pushing to unauth'
887 push not authorized
882 push not authorized
888 [1]
883 [1]
889
884
890 TODO batch command doesn't check permissions
891
892 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
885 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
893 200 Script output follows
886 401 push not authorized
894
887
895 1
888 0
889 push not authorized
890 [1]
896
891
897 $ hg bookmarks
892 $ hg bookmarks
898 bm 0:cb9a9f314b8b
893 no bookmarks set
899 $ hg book -d bm
900
894
901 TODO custom commands don't check permissions
895 TODO custom commands don't check permissions
902
896
@@ -945,16 +939,15 b' web.deny_push=* denies pushing to authen'
945 push not authorized
939 push not authorized
946 [1]
940 [1]
947
941
948 TODO batch command doesn't check permissions
949
950 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
942 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
951 200 Script output follows
943 401 push not authorized
952
944
953 1
945 0
946 push not authorized
947 [1]
954
948
955 $ hg bookmarks
949 $ hg bookmarks
956 bm 0:cb9a9f314b8b
950 no bookmarks set
957 $ hg book -d bm
958
951
959 TODO custom commands don't check permissions
952 TODO custom commands don't check permissions
960
953
@@ -1009,16 +1002,15 b' web.deny_push=<user> denies pushing to u'
1009 push not authorized
1002 push not authorized
1010 [1]
1003 [1]
1011
1004
1012 TODO batch command doesn't check permissions
1013
1014 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1005 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1015 200 Script output follows
1006 401 push not authorized
1016
1007
1017 1
1008 0
1009 push not authorized
1010 [1]
1018
1011
1019 $ hg bookmarks
1012 $ hg bookmarks
1020 bm 0:cb9a9f314b8b
1013 no bookmarks set
1021 $ hg book -d bm
1022
1014
1023 TODO custom commands don't check permissions
1015 TODO custom commands don't check permissions
1024
1016
@@ -1067,16 +1059,15 b' web.deny_push=<user> denies pushing to u'
1067 push not authorized
1059 push not authorized
1068 [1]
1060 [1]
1069
1061
1070 TODO batch command doesn't check permissions
1071
1072 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1062 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1073 200 Script output follows
1063 401 push not authorized
1074
1064
1075 1
1065 0
1066 push not authorized
1067 [1]
1076
1068
1077 $ hg bookmarks
1069 $ hg bookmarks
1078 bm 0:cb9a9f314b8b
1070 no bookmarks set
1079 $ hg book -d bm
1080
1071
1081 TODO custom commands don't check permissions
1072 TODO custom commands don't check permissions
1082
1073
@@ -1241,16 +1232,15 b' web.allow-push=<user> denies push to use'
1241 push not authorized
1232 push not authorized
1242 [1]
1233 [1]
1243
1234
1244 TODO batch command doesn't check permissions
1245
1246 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1235 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1247 200 Script output follows
1236 401 push not authorized
1248
1237
1249 1
1238 0
1239 push not authorized
1240 [1]
1250
1241
1251 $ hg bookmarks
1242 $ hg bookmarks
1252 bm 0:cb9a9f314b8b
1243 no bookmarks set
1253 $ hg book -d bm
1254
1244
1255 TODO custom commands don't check permissions
1245 TODO custom commands don't check permissions
1256
1246
@@ -1367,16 +1357,15 b' web.deny_push takes precedence over web.'
1367 push not authorized
1357 push not authorized
1368 [1]
1358 [1]
1369
1359
1370 TODO batch command doesn't check permissions
1371
1372 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1360 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1373 200 Script output follows
1361 401 push not authorized
1374
1362
1375 1
1363 0
1364 push not authorized
1365 [1]
1376
1366
1377 $ hg bookmarks
1367 $ hg bookmarks
1378 bm 0:cb9a9f314b8b
1368 no bookmarks set
1379 $ hg book -d bm
1380
1369
1381 TODO custom commands don't check permissions
1370 TODO custom commands don't check permissions
1382
1371
@@ -1432,16 +1421,15 b' web.allow-push has no effect if web.deny'
1432 read not authorized
1421 read not authorized
1433 [1]
1422 [1]
1434
1423
1435 TODO batch command doesn't check permissions
1436
1437 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1424 $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=batch' --requestheader 'x-hgarg-1=cmds=pushkey+namespace%3Dbookmarks%2Ckey%3Dbm%2Cold%3D%2Cnew%3Dcb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b'
1438 200 Script output follows
1425 401 read not authorized
1439
1426
1440 1
1427 0
1428 read not authorized
1429 [1]
1441
1430
1442 $ hg bookmarks
1431 $ hg bookmarks
1443 bm 0:cb9a9f314b8b
1432 no bookmarks set
1444 $ hg book -d bm
1445
1433
1446 TODO custom commands don't check permissions
1434 TODO custom commands don't check permissions
1447
1435
General Comments 0
You need to be logged in to leave comments. Login now