Skip to content

Commit 8f1bf43

Browse files
committed
Merge branch 'mc-1.19.x' into mc-1.20.x
2 parents 9a48b53 + aaf8c24 commit 8f1bf43

File tree

6 files changed

+59
-28
lines changed

6 files changed

+59
-28
lines changed

Diff for: gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ kotlin.jvm.target.validation.mode=error
1010

1111
# Mod properties
1212
isUnstable=false
13-
modVersion=1.106.0
13+
modVersion=1.106.1
1414

1515
# Minecraft properties: We want to configure this here so we can read it in settings.gradle
1616
mcVersion=1.20.1

Diff for: projects/core/src/main/java/dan200/computercraft/core/apis/http/options/AddressPredicate.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.google.common.net.InetAddresses;
88

9+
import java.net.Inet4Address;
910
import java.net.Inet6Address;
1011
import java.net.InetAddress;
1112
import java.net.InetSocketAddress;
@@ -113,7 +114,6 @@ final class PrivatePattern implements AddressPredicate {
113114

114115
private static final Set<InetAddress> additionalAddresses = Arrays.stream(new String[]{
115116
// Block various cloud providers internal IPs.
116-
"100.100.100.200", // Alibaba
117117
"192.0.0.192", // Oracle
118118
}).map(InetAddresses::forString).collect(Collectors.toUnmodifiableSet());
119119

@@ -126,6 +126,7 @@ public boolean matches(InetAddress socketAddress) {
126126
|| socketAddress.isSiteLocalAddress() // 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fec0::/10
127127
|| socketAddress.isMulticastAddress() // 224.0.0.0/4, ff00::/8
128128
|| isUniqueLocalAddress(socketAddress) // fd00::/8
129+
|| isCarrierGradeNatAddress(socketAddress) // 100.64.0.0/10
129130
|| additionalAddresses.contains(socketAddress);
130131
}
131132

@@ -141,6 +142,19 @@ private boolean isUniqueLocalAddress(InetAddress address) {
141142
// defined right now, so let's be conservative.
142143
return address instanceof Inet6Address && (address.getAddress()[0] & 0xff) == 0xfd;
143144
}
145+
146+
/**
147+
* Determine if an IP address lives within the CGNAT address range (100.64.0.0/10).
148+
*
149+
* @param address The IP address to test.
150+
* @return Whether this address sits in the CGNAT address range.
151+
* @see <a href="https://en.wikipedia.org/wiki/Carrier-grade_NAT">Carrier-grade NAT on Wikipedia</a>
152+
*/
153+
private boolean isCarrierGradeNatAddress(InetAddress address) {
154+
if (!(address instanceof Inet4Address)) return false;
155+
var bytes = address.getAddress();
156+
return bytes[0] == 100 && ((bytes[1] & 0xFF) >= 64 && (bytes[1] & 0xFF) <= 127);
157+
}
144158
}
145159

146160
}

Diff for: projects/core/src/main/resources/data/computercraft/lua/rom/help/changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# New features in CC: Tweaked 1.106.1
2+
3+
Several bug fixes:
4+
* Block the CGNAT range (100.64.0.0/10) by default.
5+
* Fix conflicts with other mods replacing reach distance.
6+
17
# New features in CC: Tweaked 1.106.0
28

39
* Numerous documentation improvements (MCJack123, znepb, penguinencounter).
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
New features in CC: Tweaked 1.106.0
2-
3-
* Numerous documentation improvements (MCJack123, znepb, penguinencounter).
4-
* Port `fs.find` to Lua. This also allows using `?` as a wildcard.
5-
* Computers cursors now glow in the dark.
6-
* Allow changing turtle upgrades from the GUI.
7-
* Add option to serialize Unicode strings to JSON (MCJack123).
8-
* Small optimisations to the `window` API.
9-
* Turtle upgrades can now preserve NBT from upgrade item stack and when broken.
10-
* Add support for tool enchantments and durability via datapacks. This is disabled for the built-in tools.
1+
New features in CC: Tweaked 1.106.1
112

123
Several bug fixes:
13-
* Fix turtles rendering incorrectly when upside down.
14-
* Fix misplaced calls to IArguments.escapes.
15-
* Lua REPL no longer accepts `)(` as a valid expression.
16-
* Fix several inconsistencies with `require`/`package.path` in the Lua REPL (Wojbie).
17-
* Fix turtle being able to place water buckets outside its reach distance.
18-
* Fix private several IP address ranges not being blocked by the `$private` rule.
19-
* Improve permission checks in the `/computercraft` command.
4+
* Block the CGNAT range (100.64.0.0/10) by default.
5+
* Fix conflicts with other mods replacing reach distance.
206

217
Type "help changelog" to see the full version history.

Diff for: projects/core/src/test/java/dan200/computercraft/core/apis/http/options/AddressRuleTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public void matchesPort() {
3434
"172.17.0.1", "192.168.1.114", "[0:0:0:0:0:ffff:c0a8:172]", "10.0.0.1",
3535
// Multicast
3636
"224.0.0.1", "ff02::1",
37+
// CGNAT
38+
"100.64.0.0", "100.127.255.255",
3739
// Cloud metadata providers
3840
"100.100.100.200", // Alibaba
3941
"192.0.0.192", // Oracle
@@ -44,6 +46,15 @@ public void blocksLocalDomains(String domain) {
4446
assertEquals(apply(CoreConfig.httpRules, domain, 80).action, Action.DENY);
4547
}
4648

49+
@ParameterizedTest
50+
@ValueSource(strings = {
51+
// Ensure either side of the CGNAT range is allowed.
52+
"100.63.255.255", "100.128.0.0"
53+
})
54+
public void allowsNonLocalDomains(String domain) {
55+
assertEquals(apply(CoreConfig.httpRules, domain, 80).action, Action.ALLOW);
56+
}
57+
4758
private Options apply(Iterable<AddressRule> rules, String host, int port) {
4859
return AddressRule.apply(rules, host, new InetSocketAddress(host, port));
4960
}

Diff for: projects/fabric/src/main/java/dan200/computercraft/mixin/ItemMixin.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,38 @@
99
import net.minecraft.world.item.Item;
1010
import net.minecraft.world.level.ClipContext;
1111
import net.minecraft.world.level.Level;
12+
import net.minecraft.world.phys.BlockHitResult;
1213
import org.spongepowered.asm.mixin.Mixin;
13-
import org.spongepowered.asm.mixin.injection.Constant;
14-
import org.spongepowered.asm.mixin.injection.ModifyConstant;
14+
import org.spongepowered.asm.mixin.Unique;
15+
import org.spongepowered.asm.mixin.injection.At;
16+
import org.spongepowered.asm.mixin.injection.Inject;
17+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1518

1619
@Mixin(Item.class)
1720
class ItemMixin {
1821
/**
1922
* Replace the reach distance in {@link Item#getPlayerPOVHitResult(Level, Player, ClipContext.Fluid)}.
2023
*
21-
* @param reach The original reach distance.
22-
* @param level The current level.
23-
* @param player The current player.
24-
* @return The new reach distance.
24+
* @param level The current level.
25+
* @param player The current player.
26+
* @param fluidMode The current clip-context fluid mode.
27+
* @param cir Callback info to store the new reach distance.
2528
* @see FakePlayer#getBlockReach()
2629
*/
27-
@ModifyConstant(method = "getPlayerPOVHitResult", constant = @Constant(doubleValue = 5))
30+
@Inject(method = "getPlayerPOVHitResult", at = @At("HEAD"), cancellable = true)
2831
@SuppressWarnings("UnusedMethod")
29-
private static double getReachDistance(double reach, Level level, Player player) {
30-
return player instanceof FakePlayer fp ? fp.getBlockReach() : reach;
32+
private static void getReachDistance(Level level, Player player, ClipContext.Fluid fluidMode, CallbackInfoReturnable<BlockHitResult> cir) {
33+
// It would theoretically be cleaner to use @ModifyConstant here, but as it's treated as a @Redirect, it doesn't
34+
// compose with other mods. Instead, we replace the method when working with our fake player.
35+
if (player instanceof FakePlayer fp) cir.setReturnValue(getHitResult(level, fp, fluidMode));
36+
}
37+
38+
@Unique
39+
private static BlockHitResult getHitResult(Level level, FakePlayer player, ClipContext.Fluid fluidMode) {
40+
var start = player.getEyePosition();
41+
var reach = player.getBlockReach();
42+
var direction = player.getViewVector(1.0f);
43+
var end = start.add(direction.x() * reach, direction.y() * reach, direction.z() * reach);
44+
return level.clip(new ClipContext(start, end, ClipContext.Block.OUTLINE, fluidMode, player));
3145
}
3246
}

0 commit comments

Comments
 (0)