This is not a problem with the A* algorithm. It's a problem with the data you've given it as input.
At some point in the algorithm, A* asks your map to enumerate the neighbouring nodes reachable from the node it's currently examining.
At this point, if the node (1, 1) is not supposed to be reachable from the current node (2, 2), it's the responsibility of your map / neighbour iteration to not offer (1, 1) as an option for the algorithm to consider. If you give it that as an option, you're saying "paths that pass from that node to this node are valid".
So for example, if your neighbour-enumerating function looks like this, visiting all 8 neighbours of a node, including diagonals:
IEnumerator<Node> GetNeighbours(Node source) {
for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) {
if(x== 0 && y == 0)
continue;
if(!map.IsInBounds(source.x + x, source.y + y)
continue;
var node = map.GetNode(source.x + x, source.y + y);
yield return node;
}
}
}
...then you likely want to restrict it to visit only the four orthogonal neighbours instead:
IEnumerator<Node> GetNeighbours(Node source) {
if(map.IsInBounds(source.x - 1, source.y);
yield return map.GetNode(source.x - 1, source.y);
if(map.IsInBounds(source.x, source.y - 1);
yield return map.GetNode(source.x, source.y - 1);
if(map.IsInBounds(source.x + 1, source.y);
yield return map.GetNode(source.x + 1, source.y);
if(map.IsInBounds(source.x, source.y + 1);
yield return map.GetNode(source.x, source.y + 1);
}